Skip to content

Commit

Permalink
feat: Update advanced/bigquery.gs sample (googleworkspace#378)
Browse files Browse the repository at this point in the history
Sample uses `TOP` which is an invalid BQ function. Replace sample with query from https://cloud.google.com/bigquery/docs/sandbox.
  • Loading branch information
vinay-google authored Jan 25, 2023
1 parent 108e648 commit 1a3f358
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions advanced/bigquery.gs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ function runQuery() {

const request = {
// TODO (developer) - Replace query with yours
query: 'SELECT TOP(word, 300) AS word, COUNT(*) AS word_count ' +
'FROM `publicdata.samples.shakespeare` WHERE LENGTH(word) > 10;',
query: 'SELECT refresh_date AS Day, term AS Top_Term, rank ' +
'FROM `bigquery-public-data.google_trends.top_terms` ' +
'WHERE rank = 1 ' +
'AND refresh_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 2 WEEK) ' +
'GROUP BY Day, Top_Term, rank ' +
'ORDER BY Day DESC;',
useLegacySql: false
};
let queryResults = BigQuery.Jobs.query(request, projectId);
Expand All @@ -52,7 +56,7 @@ function runQuery() {
console.log('No rows returned.');
return;
}
const spreadsheet = SpreadsheetApp.create('BiqQuery Results');
const spreadsheet = SpreadsheetApp.create('BigQuery Results');
const sheet = spreadsheet.getActiveSheet();

// Append the headers.
Expand All @@ -72,8 +76,7 @@ function runQuery() {
}
sheet.getRange(2, 1, rows.length, headers.length).setValues(data);

console.log('Results spreadsheet created: %s',
spreadsheet.getUrl());
console.log('Results spreadsheet created: %s', spreadsheet.getUrl());
}
// [END apps_script_bigquery_run_query]

Expand Down

0 comments on commit 1a3f358

Please sign in to comment.