Skip to content

Commit a258c96

Browse files
author
Ace Nassri
authored
Add (missing) sample parameter values (#428)
* Add example queries to samples * Add more example parameters * Updates README and cleans up package.json (#431) * Add build client sample
1 parent 3a50b3b commit a258c96

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

bigquery/queries.js

+21-12
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
'use strict';
1717

1818
// [START bigquery_simple_app_all]
19-
// [START bigquery_simple_app_print]
2019
function printResult (rows) {
20+
// [START bigquery_simple_app_print]
2121
console.log('Query Results:');
2222
rows.forEach(function (row) {
2323
let str = '';
@@ -29,25 +29,26 @@ function printResult (rows) {
2929
}
3030
console.log(str);
3131
});
32+
// [END bigquery_simple_app_print]
3233
}
33-
// [END bigquery_simple_app_print]
34-
35-
// [START bigquery_simple_app_query]
36-
const sqlQuery = `SELECT
37-
corpus, COUNT(*) as unique_words
38-
FROM publicdata.samples.shakespeare
39-
GROUP BY
40-
corpus
41-
ORDER BY
42-
unique_words DESC LIMIT 10;`;
4334

4435
function queryShakespeare (projectId) {
36+
// [START bigquery_simple_app_query]
4537
// Imports the Google Cloud client library
4638
const BigQuery = require('@google-cloud/bigquery');
4739

4840
// The project ID to use, e.g. "your-project-id"
4941
// const projectId = "your-project-id";
5042

43+
// The SQL query to run
44+
const sqlQuery = `SELECT
45+
corpus, COUNT(*) as unique_words
46+
FROM publicdata.samples.shakespeare
47+
GROUP BY
48+
corpus
49+
ORDER BY
50+
unique_words DESC LIMIT 10;`;
51+
5152
// Instantiates a client
5253
const bigquery = BigQuery({
5354
projectId: projectId
@@ -69,8 +70,8 @@ function queryShakespeare (projectId) {
6970
.catch((err) => {
7071
console.error('ERROR:', err);
7172
});
73+
// [END bigquery_simple_app_query]
7274
}
73-
// [END bigquery_simple_app_query]
7475
// [END bigquery_simple_app_all]
7576

7677
function syncQuery (sqlQuery, projectId) {
@@ -81,6 +82,9 @@ function syncQuery (sqlQuery, projectId) {
8182
// The project ID to use, e.g. "your-project-id"
8283
// const projectId = "your-project-id";
8384

85+
// The SQL query to run, e.g. "SELECT * FROM publicdata.samples.natality LIMIT 5;"
86+
// const sqlQuery = "SELECT * FROM publicdata.samples.natality LIMIT 5;";
87+
8488
// Instantiates a client
8589
const bigquery = BigQuery({
8690
projectId: projectId
@@ -109,6 +113,7 @@ function syncQuery (sqlQuery, projectId) {
109113

110114
function asyncQuery (sqlQuery, projectId) {
111115
// [START bigquery_async_query]
116+
// [START bigquery_build_client]
112117
// Imports the Google Cloud client library
113118
const BigQuery = require('@google-cloud/bigquery');
114119

@@ -119,6 +124,10 @@ function asyncQuery (sqlQuery, projectId) {
119124
const bigquery = BigQuery({
120125
projectId: projectId
121126
});
127+
// [END bigquery_build_client]
128+
129+
// The SQL query to run, e.g. "SELECT * FROM publicdata.samples.natality LIMIT 5;"
130+
// const sqlQuery = "SELECT * FROM publicdata.samples.natality LIMIT 5;";
122131

123132
// Query options list: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query
124133
const options = {

bigquery/tables.js

+7
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ function listTables (datasetId, projectId) {
9797
// The project ID to use, e.g. "your-project-id"
9898
// const projectId = "your-project-id";
9999

100+
// The ID of the dataset to list tables in, e.g. "my_dataset"
101+
// const datasetId = "my_dataset";
102+
100103
// Instantiates a client
101104
const bigquery = BigQuery({
102105
projectId: projectId
@@ -401,6 +404,10 @@ function insertRowsAsStream (datasetId, tableId, rows, projectId) {
401404
// The ID of the table into which data should be inserted, e.g. "my_table"
402405
// const tableId = "my_table";
403406

407+
// The rows to insert into the table
408+
// Customize this object to match your table's schema
409+
// const rows = [{name: "Tom", age: 30}, {name: "Jane", age: 32}];
410+
404411
// Instantiates a client
405412
const bigquery = BigQuery({
406413
projectId: projectId

0 commit comments

Comments
 (0)