Last active
August 12, 2016 10:51
-
-
Save sAbakumoff/b229149ac9f0de50305c302d099e1238 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_keywords(r, emit) { | |
try{ | |
var package=JSON.parse(r.content); | |
(package.keywords || []).forEach(function(keyword){ | |
emit({keyword : keyword}); | |
}); | |
} | |
catch(ex){ | |
} | |
} | |
bigquery.defineFunction( | |
'select_keywords', // Name of the function exported to SQL | |
['content'], // Names of input columns | |
[{'name': 'keyword', 'type': 'string'}], // Output schema | |
select_keywords // Reference to JavaScript UDF | |
); | |
SELECT | |
keyword, | |
COUNT(keyword) AS count | |
FROM ( | |
SELECT | |
keyword | |
FROM (select_keywords( | |
SELECT | |
content | |
FROM | |
[githubdataqueries:NpmStat.package_json_content] )) ) | |
GROUP BY | |
keyword | |
ORDER BY | |
count DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment