From d58d5ace4ee5204a80ae8647cade2989acdcb25f Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Wed, 9 Nov 2022 17:14:17 -0400 Subject: [PATCH 1/7] feat: add set client endpoint sample --- samples/setClientEndpoint.js | 29 +++++++++++++++++++++++++++++ samples/test/clients.test.js | 9 +++++++++ samples/test/datasets.test.js | 25 +++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 samples/setClientEndpoint.js diff --git a/samples/setClientEndpoint.js b/samples/setClientEndpoint.js new file mode 100644 index 00000000..a588efd4 --- /dev/null +++ b/samples/setClientEndpoint.js @@ -0,0 +1,29 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +async function main(region = "us") { + // [START bigquery_set_client_endpoint] + // Import the Google Cloud client library + const {BigQuery} = require('@google-cloud/bigquery'); + // Create a client and pointing to a specific endpoint + const bigquery = new BigQuery({ + apiEndpoint: `${region}-bigquery.googleapis.com` + }); + + console.log('API Endpoint:'); + console.log(bigquery.apiEndpoint); +} +main(...process.argv.slice(2)); diff --git a/samples/test/clients.test.js b/samples/test/clients.test.js index a81e5a7e..f7f5b491 100644 --- a/samples/test/clients.test.js +++ b/samples/test/clients.test.js @@ -26,4 +26,13 @@ describe('Client', () => { assert.match(output, /User agent:/); assert.match(output, /my-user-agent/); }); + it('should should set client endpoint', async () => { + let output = execSync(`node setClientEndpoint.js us-east4`); + assert.match(output, /API Endpoint:/); + assert.match(output, /https:\/\/us-east4-bigquery.googleapis.com/); + + output = execSync(`node setClientEndpoint.js eu`); + assert.match(output, /API Endpoint:/); + assert.match(output, /https:\/\/eu-bigquery.googleapis.com/); + }); }); diff --git a/samples/test/datasets.test.js b/samples/test/datasets.test.js index 93cf2011..45f14d4c 100644 --- a/samples/test/datasets.test.js +++ b/samples/test/datasets.test.js @@ -49,6 +49,31 @@ describe('Datasets', () => { assert.ok(exists); }); + it('should create a dataset using a regional endpoint', async () => { + const euBigquery = new BigQuery({apiEndpoint: 'eu-bigquery.googleapis.com'}); + const euDatasetId = datasetId + "_eu"; + await euBigquery.createDataset(euDatasetId, { + location: "eu", + }); + const [exists] = await euBigquery.dataset(euDatasetId).exists(); + assert.ok(exists); + }); + + it('should fail to create a dataset using a different region from the client endpoint', async () => { + const usEast4Bigquery = new BigQuery({apiEndpoint: 'us-east4-bigquery.googleapis.com'}); + const usDatasetId = datasetId + "_us"; + var error + try { + await usEast4Bigquery.createDataset(usDatasetId, { + location: "us-central1", + }); + } catch(err){ + error = err + } + assert.isNotNull(error) + assert.equal(error.message, "Invalid storage region") + }); + it('should list datasets', async () => { const output = execSync('node listDatasets.js'); assert.match(output, /Datasets:/); From 81a87d1b7a9d12a82b02c940309a5f1f44cd2e10 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Wed, 9 Nov 2022 17:27:28 -0400 Subject: [PATCH 2/7] fix: lint issues --- samples/setClientEndpoint.js | 6 +++--- samples/test/clients.test.js | 4 ++-- samples/test/datasets.test.js | 26 +++++++++++++++----------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/samples/setClientEndpoint.js b/samples/setClientEndpoint.js index a588efd4..7646c59b 100644 --- a/samples/setClientEndpoint.js +++ b/samples/setClientEndpoint.js @@ -14,13 +14,13 @@ 'use strict'; -async function main(region = "us") { +async function main(region = 'us') { // [START bigquery_set_client_endpoint] // Import the Google Cloud client library const {BigQuery} = require('@google-cloud/bigquery'); // Create a client and pointing to a specific endpoint - const bigquery = new BigQuery({ - apiEndpoint: `${region}-bigquery.googleapis.com` + const bigquery = new BigQuery({ + apiEndpoint: `${region}-bigquery.googleapis.com`, }); console.log('API Endpoint:'); diff --git a/samples/test/clients.test.js b/samples/test/clients.test.js index f7f5b491..cb6f1aeb 100644 --- a/samples/test/clients.test.js +++ b/samples/test/clients.test.js @@ -27,11 +27,11 @@ describe('Client', () => { assert.match(output, /my-user-agent/); }); it('should should set client endpoint', async () => { - let output = execSync(`node setClientEndpoint.js us-east4`); + let output = execSync('node setClientEndpoint.js us-east4'); assert.match(output, /API Endpoint:/); assert.match(output, /https:\/\/us-east4-bigquery.googleapis.com/); - output = execSync(`node setClientEndpoint.js eu`); + output = execSync('node setClientEndpoint.js eu'); assert.match(output, /API Endpoint:/); assert.match(output, /https:\/\/eu-bigquery.googleapis.com/); }); diff --git a/samples/test/datasets.test.js b/samples/test/datasets.test.js index 45f14d4c..66f56c46 100644 --- a/samples/test/datasets.test.js +++ b/samples/test/datasets.test.js @@ -50,28 +50,32 @@ describe('Datasets', () => { }); it('should create a dataset using a regional endpoint', async () => { - const euBigquery = new BigQuery({apiEndpoint: 'eu-bigquery.googleapis.com'}); - const euDatasetId = datasetId + "_eu"; + const euBigquery = new BigQuery({ + apiEndpoint: 'eu-bigquery.googleapis.com', + }); + const euDatasetId = datasetId + '_eu'; await euBigquery.createDataset(euDatasetId, { - location: "eu", + location: 'eu', }); const [exists] = await euBigquery.dataset(euDatasetId).exists(); assert.ok(exists); }); it('should fail to create a dataset using a different region from the client endpoint', async () => { - const usEast4Bigquery = new BigQuery({apiEndpoint: 'us-east4-bigquery.googleapis.com'}); - const usDatasetId = datasetId + "_us"; - var error + const usEast4Bigquery = new BigQuery({ + apiEndpoint: 'us-east4-bigquery.googleapis.com', + }); + const usDatasetId = datasetId + '_us'; + let error; try { await usEast4Bigquery.createDataset(usDatasetId, { - location: "us-central1", + location: 'us-central1', }); - } catch(err){ - error = err + } catch (err) { + error = err; } - assert.isNotNull(error) - assert.equal(error.message, "Invalid storage region") + assert.isNotNull(error); + assert.equal(error.message, 'Invalid storage region'); }); it('should list datasets', async () => { From 5cc1e59d7f8ccc77013b6aea0a9695160527cf46 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 22 Nov 2022 08:30:40 -0400 Subject: [PATCH 3/7] fix: add region tag and remove async function --- samples/setClientEndpoint.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/setClientEndpoint.js b/samples/setClientEndpoint.js index 7646c59b..6135c53f 100644 --- a/samples/setClientEndpoint.js +++ b/samples/setClientEndpoint.js @@ -14,10 +14,11 @@ 'use strict'; -async function main(region = 'us') { +function main(region = 'us') { // [START bigquery_set_client_endpoint] // Import the Google Cloud client library const {BigQuery} = require('@google-cloud/bigquery'); + // Create a client and pointing to a specific endpoint const bigquery = new BigQuery({ apiEndpoint: `${region}-bigquery.googleapis.com`, @@ -25,5 +26,6 @@ async function main(region = 'us') { console.log('API Endpoint:'); console.log(bigquery.apiEndpoint); + // [END bigquery_set_client_endpoint] } main(...process.argv.slice(2)); From d4761bb4d1c66edb5ac4d9f6f59ad1db40b48ff7 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 22 Nov 2022 08:56:43 -0400 Subject: [PATCH 4/7] fix: move example to internal function --- samples/setClientEndpoint.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/samples/setClientEndpoint.js b/samples/setClientEndpoint.js index 6135c53f..fd6ce90e 100644 --- a/samples/setClientEndpoint.js +++ b/samples/setClientEndpoint.js @@ -18,14 +18,23 @@ function main(region = 'us') { // [START bigquery_set_client_endpoint] // Import the Google Cloud client library const {BigQuery} = require('@google-cloud/bigquery'); - - // Create a client and pointing to a specific endpoint - const bigquery = new BigQuery({ - apiEndpoint: `${region}-bigquery.googleapis.com`, - }); - console.log('API Endpoint:'); - console.log(bigquery.apiEndpoint); + function setClientEndpoint() { + // Create a bigquery client pointing to a specific endpoint + + /** + * TODO(developer): Uncomment the following lines before running the sample. + */ + // const region = 'us'; + + const bigquery = new BigQuery({ + apiEndpoint: `${region}-bigquery.googleapis.com`, + }); + + console.log('API Endpoint:'); + console.log(bigquery.apiEndpoint); + } // [END bigquery_set_client_endpoint] + setClientEndpoint(); } main(...process.argv.slice(2)); From b3d2df58581b168961986b63269f69be8a2ccecd Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 6 Dec 2022 18:46:19 -0400 Subject: [PATCH 5/7] fix(bigquery): follow parameter style guide for samples --- samples/setClientEndpoint.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/setClientEndpoint.js b/samples/setClientEndpoint.js index fd6ce90e..da582388 100644 --- a/samples/setClientEndpoint.js +++ b/samples/setClientEndpoint.js @@ -14,7 +14,7 @@ 'use strict'; -function main(region = 'us') { +function main(region = 'my-region') { // [START bigquery_set_client_endpoint] // Import the Google Cloud client library const {BigQuery} = require('@google-cloud/bigquery'); @@ -23,9 +23,9 @@ function main(region = 'us') { // Create a bigquery client pointing to a specific endpoint /** - * TODO(developer): Uncomment the following lines before running the sample. + * TODO(developer): Uncomment the following line of code and fill in your region before running the sample. */ - // const region = 'us'; + // const region = 'my-region'; const bigquery = new BigQuery({ apiEndpoint: `${region}-bigquery.googleapis.com`, From b101b239286461d11a7fe3be6db780e113a3923f Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Fri, 13 Jan 2023 10:44:44 -0400 Subject: [PATCH 6/7] fix: update license file header with 2023 --- samples/setClientEndpoint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/setClientEndpoint.js b/samples/setClientEndpoint.js index da582388..5ec8575d 100644 --- a/samples/setClientEndpoint.js +++ b/samples/setClientEndpoint.js @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. From b0c6a1bc7c1f1e542763b54a5e54195489023335 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 24 Jan 2023 23:57:24 +0000 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 1 + samples/README.md | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 3961a512..72801ad4 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-bigquery/tr | Relax Column Load Append | [source code](https://github.com/googleapis/nodejs-bigquery/blob/main/samples/relaxColumnLoadAppend.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-bigquery&page=editor&open_in_editor=samples/relaxColumnLoadAppend.js,samples/README.md) | | Relax Column Query Append | [source code](https://github.com/googleapis/nodejs-bigquery/blob/main/samples/relaxColumnQueryAppend.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-bigquery&page=editor&open_in_editor=samples/relaxColumnQueryAppend.js,samples/README.md) | | Remove Table Clustering | [source code](https://github.com/googleapis/nodejs-bigquery/blob/main/samples/removeTableClustering.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-bigquery&page=editor&open_in_editor=samples/removeTableClustering.js,samples/README.md) | +| Set Client Endpoint | [source code](https://github.com/googleapis/nodejs-bigquery/blob/main/samples/setClientEndpoint.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-bigquery&page=editor&open_in_editor=samples/setClientEndpoint.js,samples/README.md) | | Set User Agent | [source code](https://github.com/googleapis/nodejs-bigquery/blob/main/samples/setUserAgent.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-bigquery&page=editor&open_in_editor=samples/setUserAgent.js,samples/README.md) | | Table Exists | [source code](https://github.com/googleapis/nodejs-bigquery/blob/main/samples/tableExists.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-bigquery&page=editor&open_in_editor=samples/tableExists.js,samples/README.md) | | Undelete Table | [source code](https://github.com/googleapis/nodejs-bigquery/blob/main/samples/undeleteTable.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-bigquery&page=editor&open_in_editor=samples/undeleteTable.js,samples/README.md) | diff --git a/samples/README.md b/samples/README.md index 88cdbd52..71ad7f52 100644 --- a/samples/README.md +++ b/samples/README.md @@ -102,6 +102,7 @@ * [Relax Column Load Append](#relax-column-load-append) * [Relax Column Query Append](#relax-column-query-append) * [Remove Table Clustering](#remove-table-clustering) + * [Set Client Endpoint](#set-client-endpoint) * [Set User Agent](#set-user-agent) * [Table Exists](#table-exists) * [Undelete Table](#undelete-table) @@ -1678,6 +1679,23 @@ __Usage:__ +### Set Client Endpoint + +View the [source code](https://github.com/googleapis/nodejs-bigquery/blob/main/samples/setClientEndpoint.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-bigquery&page=editor&open_in_editor=samples/setClientEndpoint.js,samples/README.md) + +__Usage:__ + + +`node samples/setClientEndpoint.js` + + +----- + + + + ### Set User Agent View the [source code](https://github.com/googleapis/nodejs-bigquery/blob/main/samples/setUserAgent.js).