Last active
October 26, 2016 14:59
-
-
Save sAbakumoff/95f81b11bbe4610f8509c1650d25b8f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function select_framework(r, emit) { | |
try{ | |
var package=JSON.parse(r.content); | |
if(package && package.dependencies){ | |
var deps = Object.keys(package.dependencies); | |
if(deps.indexOf("react")>=0){ | |
var row = {id:r.id, repo:r.repo, name:package.name}; | |
deps.forEach(function(dep){ | |
emit(Object.assign({}, row, {dependency : dep, isDev : 0 })); | |
}); | |
Object.keys(package.devDependencies).forEach(function(dep){ | |
emit(Object.assign({}, row, {dependency : dep, isDev : 1 })); | |
}); | |
} | |
} | |
} | |
catch(ex){ | |
} | |
} | |
bigquery.defineFunction( | |
'select_framework', | |
['id', 'repo', 'content'], | |
[{'name': 'id', 'type': 'string'}, | |
{"name" : "repo", "type" : "string"}, | |
{"name" : "name", "type" : "string"}, | |
{"name":"dependency", "type" : "string"}, | |
{"name":"isDev", "type" : "integer"} | |
], | |
select_framework | |
); | |
SELECT repo, name, dependency, isDev | |
FROM | |
select_framework( | |
SELECT contents.id id, files.repo repo, contents.content content | |
FROM ( | |
SELECT id, FIRST(repo_name) repo | |
FROM | |
[bigquery-public-data:github_repos.files] | |
WHERE | |
path = 'package.json' | |
GROUP BY | |
id ) files | |
JOIN | |
[bigquery-public-data:github_repos.contents] contents | |
ON | |
files.id=contents.id ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment