function decodeHelper(s) { try { return decodeURI(s); } catch (ex) { return s; } } // The UDF. function urlDecode(r, emit) { emit({title: decodeHelper(r.title), requests: r.num_requests}); }
bigquery.defineFunction( 'urlDecode', // Name used to call the function from SQL. ['title', 'num_requests'], // Input column names. // JSON representation of output schema. [{name: 'title', type: 'string'}, {name: 'requests', type: 'integer'}], urlDecode // The UDF reference. );
SELECT requests, title FROM urlDecode( SELECT title, sum(requests) AS num_requests FROM [fh-bigquery:wikipedia.pagecounts_201504] WHERE language = 'fr' GROUP EACH BY title ) WHERE title LIKE '%ç%' ORDER BY requests DESC LIMIT 100
// myCode.js var numRows = 0; function dontDoThis(r, emit) { emit(rowCount: ++numRows); } // The query. SELECT max(rowCount) FROM dontDoThis(myTable);