You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#standardSQLSELECT repo_name, max(committer.date) as last_date
FROM`bigquery-public-data.github_repos.commits` t1,
t1.differenceas difference,
UNNEST(repo_name) as repo_name
WHEREdifference.new_pathLIKE'package.json'GROUP BY repo_name
SELECT id, repo_name, last_date, dependency, type, version
FROM getDependencies(
SELECT
id,
repo_name,
last_date,
JSON_EXTRACT(content, '$.dependencies') AS dependencies,
JSON_EXTRACT(content, '$.devDependencies') AS devDependencies
FROM [package-json-files-with-date]
)
// The UDFfunctiongetDependencies(row,emit){emitResults(row,emit,'dependencies');emitResults(row,emit,'devDependencies');}functionemitResults(row,emit,type){if(row[type]){x=JSON.parse(row[type])if(x!==null&&typeofx==='object'){Object.keys(x).forEach(function(entry){if(validDependency(x,entry)){emit({id: row.id,repo_name: row.repo_name,last_date: row.last_date,repo_name: row.repo_name,dependency: entry,type: type,version: decodeDependencyHelper(x,entry)});}});}}}functionvalidDependency(x,entry){returnentry!=''&&decodeDependencyHelper(x,entry)!='';}functiondecodeDependencyHelper(x,entry){varreturnVal=x[entry];returntypeofreturnVal==='string' ? returnVal : ''+returnVal;}bigquery.defineFunction('getDependencies',// Name used to call the function from SQL['id','repo_name','last_date','dependencies','devDependencies'],// Input column names// JSON representation of the output schema[{name: 'id',type: 'string'},{name: 'repo_name',type: 'string'},{name: 'last_date',type: 'timestamp'},{name: 'dependency',type: 'string'},{name: 'type',type: 'string'},{name: 'version',type: 'string'},],getDependencies// The function reference);
frameworks-in-dependencies
SELECTa.year_dateas year_date,
a.month_dateas month_date,
a.dependencyas dependency,
a.dependency_countas dependency_count,
b.occurenceas occurence,
(a.dependency_count*100) /b.occurenceas percent
FROM (
SELECT
YEAR(last_date) as year_date,
MONTH(last_date) as month_date,
dependency,
COUNT(dependency) as dependency_count
FROM (
Select
repo_name,
dependency,
max(last_date) as last_date,
max(type) as type,
max(version) as version,
max(id) as id
from [package-json-dependencies]
where type ="dependencies"Group by repo_name, dependency
)
WHERE repo_name in (
SELECT repo_name
FROM [package-json-dependencies]
GROUP BY repo_name
)
GROUP BY year_date, month_date, dependency
) a
INNER JOIN (
SELECT
YEAR(last_date) as year_date,
MONTH(last_date) as month_date,
count(distinct repo_name) as occurence
FROM (
Select
repo_name,
dependency,
max(last_date) as last_date,
max(type) as type,
max(version) as version,
max(id) as id
from [package-json-dependencies]
where type ="dependencies"Group by repo_name, dependency
)
WHERE repo_name in (
SELECT repo_name
FROM [package-json-dependencies]
GROUP BY repo_name
)
GROUP BY year_date, month_date
) b ONa.year_date=b.year_dateANDa.month_date=b.month_dateWHERE dependency IN (
'jquery',
'react',
'backbone',
'@angular/core',
'vue',
'angular',
)
ORDER BY year_date DESC, month_date DESC, percent DESC