Skip to content

Commit

Permalink
Add (missing) sample parameter values (#428)
Browse files Browse the repository at this point in the history
* Add example queries to samples

* Add more example parameters

* Updates README and cleans up package.json (#431)

* Add build client sample
  • Loading branch information
Ace Nassri authored Jul 24, 2017
1 parent 3a50b3b commit a258c96
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
33 changes: 21 additions & 12 deletions bigquery/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
'use strict';

// [START bigquery_simple_app_all]
// [START bigquery_simple_app_print]
function printResult (rows) {
// [START bigquery_simple_app_print]
console.log('Query Results:');
rows.forEach(function (row) {
let str = '';
Expand All @@ -29,25 +29,26 @@ function printResult (rows) {
}
console.log(str);
});
// [END bigquery_simple_app_print]
}
// [END bigquery_simple_app_print]

// [START bigquery_simple_app_query]
const sqlQuery = `SELECT
corpus, COUNT(*) as unique_words
FROM publicdata.samples.shakespeare
GROUP BY
corpus
ORDER BY
unique_words DESC LIMIT 10;`;

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

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

// The SQL query to run
const sqlQuery = `SELECT
corpus, COUNT(*) as unique_words
FROM publicdata.samples.shakespeare
GROUP BY
corpus
ORDER BY
unique_words DESC LIMIT 10;`;

// Instantiates a client
const bigquery = BigQuery({
projectId: projectId
Expand All @@ -69,8 +70,8 @@ function queryShakespeare (projectId) {
.catch((err) => {
console.error('ERROR:', err);
});
// [END bigquery_simple_app_query]
}
// [END bigquery_simple_app_query]
// [END bigquery_simple_app_all]

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

// The SQL query to run, e.g. "SELECT * FROM publicdata.samples.natality LIMIT 5;"
// const sqlQuery = "SELECT * FROM publicdata.samples.natality LIMIT 5;";

// Instantiates a client
const bigquery = BigQuery({
projectId: projectId
Expand Down Expand Up @@ -109,6 +113,7 @@ function syncQuery (sqlQuery, projectId) {

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

Expand All @@ -119,6 +124,10 @@ function asyncQuery (sqlQuery, projectId) {
const bigquery = BigQuery({
projectId: projectId
});
// [END bigquery_build_client]

// The SQL query to run, e.g. "SELECT * FROM publicdata.samples.natality LIMIT 5;"
// const sqlQuery = "SELECT * FROM publicdata.samples.natality LIMIT 5;";

// Query options list: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query
const options = {
Expand Down
7 changes: 7 additions & 0 deletions bigquery/tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ function listTables (datasetId, projectId) {
// The project ID to use, e.g. "your-project-id"
// const projectId = "your-project-id";

// The ID of the dataset to list tables in, e.g. "my_dataset"
// const datasetId = "my_dataset";

// Instantiates a client
const bigquery = BigQuery({
projectId: projectId
Expand Down Expand Up @@ -401,6 +404,10 @@ function insertRowsAsStream (datasetId, tableId, rows, projectId) {
// The ID of the table into which data should be inserted, e.g. "my_table"
// const tableId = "my_table";

// The rows to insert into the table
// Customize this object to match your table's schema
// const rows = [{name: "Tom", age: 30}, {name: "Jane", age: 32}];

// Instantiates a client
const bigquery = BigQuery({
projectId: projectId
Expand Down

0 comments on commit a258c96

Please sign in to comment.