Skip to content

Commit 67bf354

Browse files
authored
feat: Update advanced/bigquery.gs sample (googleworkspace#378)
Sample uses `TOP` which is an invalid BQ function. Replace sample with query from https://cloud.google.com/bigquery/docs/sandbox.
1 parent fbec318 commit 67bf354

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

advanced/bigquery.gs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ function runQuery() {
2424

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

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

75-
console.log('Results spreadsheet created: %s',
76-
spreadsheet.getUrl());
79+
console.log('Results spreadsheet created: %s', spreadsheet.getUrl());
7780
}
7881
// [END apps_script_bigquery_run_query]
7982

0 commit comments

Comments
 (0)