From 92453fc34543767a3a1a6b539417e71e6b69dec7 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Tue, 19 Aug 2025 16:11:33 -0400 Subject: [PATCH 01/96] Export the GCRuleMaker class --- src/gc-rule-maker.ts | 75 ++++++++++++++++++++++++++++++++++++++++++++ src/index.ts | 1 + 2 files changed, 76 insertions(+) create mode 100644 src/gc-rule-maker.ts diff --git a/src/gc-rule-maker.ts b/src/gc-rule-maker.ts new file mode 100644 index 000000000..4c4c3f146 --- /dev/null +++ b/src/gc-rule-maker.ts @@ -0,0 +1,75 @@ +import {IGcRule} from './family'; +import * as protos from '../protos/protos'; + +enum RuleType { + union = 'union', + intersection = 'intersection', +} + +export interface GcRule { + maxAge?: protos.google.protobuf.IDuration | number; + maxVersions?: number; + rule?: GcRule; + ruleType?: RuleType; +} + +export class GCRuleMaker { + static makeRule(gcRule: GcRule): protos.google.bigtable.admin.v2.IGcRule { + const rules: IGcRule[] = []; + + if (gcRule.maxAge) { + rules.push({ + maxAge: gcRule.maxAge as protos.google.protobuf.IDuration, + }); + } + + if (gcRule.maxVersions) { + rules.push({ + maxNumVersions: gcRule.maxVersions, + }); + } + + if (gcRule.rule) { + rules.push(this.makeRule(gcRule.rule)); + } + + if (rules.length === 1) { + if (gcRule.ruleType === RuleType.union) { + throw new Error( + 'A union must have more than one garbage collection rule.', + ); + } + + if (gcRule.ruleType === RuleType.intersection) { + throw new Error( + 'An intersection must have more than one garbage collection rule.', + ); + } + + if ( + gcRule.ruleType === RuleType.union && + gcRule.ruleType === RuleType.intersection + ) { + throw new Error( + 'A garbage collection rule cannot be both a union and an intersection.', + ); + } + + return rules[0]; + } + + if (rules.length === 0) { + throw new Error('No garbage collection rules were specified.'); + } + + const rule = {} as protos.google.bigtable.admin.v2.IGcRule; + const ruleType = + gcRule.ruleType === RuleType.union ? 'union' : 'intersection'; + + rule[ruleType] = { + rules, + }; + + return rule; + } +} diff --git a/src/index.ts b/src/index.ts index a5ccdf63d..988c6703a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1364,4 +1364,5 @@ export { WaitForReplicationCallback, WaitForReplicationResponse, } from './table'; +export {GCRuleMaker} from './gc-rule-maker'; export {SqlTypes}; From 20da51e73c69ca25efdc63d3779c8241fdda058b Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 20 Aug 2025 10:18:10 -0400 Subject: [PATCH 02/96] Use the admin client for the first sample --- samples/tableadmin.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/samples/tableadmin.js b/samples/tableadmin.js index 6dbce3948..8177bcbe4 100644 --- a/samples/tableadmin.js +++ b/samples/tableadmin.js @@ -13,7 +13,8 @@ // limitations under the License. // Imports the Google Cloud client library -const {Bigtable} = require('@google-cloud/bigtable'); +const {Bigtable, GCRuleMaker} = require('@google-cloud/bigtable'); +const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; async function runTableOperations(instanceID, tableID) { const bigtable = new Bigtable(); @@ -64,15 +65,24 @@ async function runTableOperations(instanceID, tableID) { // Define the GC rule to retain data with max age of 5 days const maxAgeRule = { rule: { - age: { + maxAge: { // Value must be atleast 1 millisecond seconds: 60 * 60 * 24 * 5, nanos: 0, }, }, }; - - let [family] = await table.createFamily('cf1', maxAgeRule); + let [family] = await BigtableTableAdminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf1', + create: { + gcRule: GCRuleMaker.makeRule(maxAgeRule), + }, + }, + ], + }); console.log(`Created column family ${family.id}`); // [END bigtable_create_family_gc_max_age] From 239bf8a9454734f5d8ad6afcb123a845ff7aa186 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 20 Aug 2025 14:36:40 +0000 Subject: [PATCH 03/96] feat: updated samples to use GCRuleMaker --- samples/api-reference-doc-snippets/table.js | 37 +++++--- samples/tableadmin.js | 95 ++++++++++++++++----- 2 files changed, 98 insertions(+), 34 deletions(-) diff --git a/samples/api-reference-doc-snippets/table.js b/samples/api-reference-doc-snippets/table.js index 189cf2d48..412b2ed6b 100644 --- a/samples/api-reference-doc-snippets/table.js +++ b/samples/api-reference-doc-snippets/table.js @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -const {Bigtable} = require('@google-cloud/bigtable'); +const {Bigtable, GCRuleMaker} = require('@google-cloud/bigtable'); +const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const bigtable = new Bigtable(); const snippets = { @@ -88,18 +89,30 @@ const snippets = { const table = instance.table(tableId); // [START bigtable_api_create_family] - const options = {}; - // options.rule = { - // age: { - // seconds: 0, - // nanos: 5000 - // }, - // versions: 3, - // union: true - // }; + const options = { + ruleType: 'union', + rule: { + maxVersions: 3, + rule: { + maxAge: { + seconds: 0, + nanos: 5000, + }, + }, + }, + }; - table - .createFamily(familyId, options) + BigtableTableAdminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: familyId, + create: { + gcRule: GCRuleMaker.makeRule(options), + }, + }, + ], + }) .then(result => { const family = result[0]; // const apiResponse = result[1]; diff --git a/samples/tableadmin.js b/samples/tableadmin.js index 8177bcbe4..68f1059a4 100644 --- a/samples/tableadmin.js +++ b/samples/tableadmin.js @@ -95,12 +95,22 @@ async function runTableOperations(instanceID, tableID) { // Define the GC policy to retain only the most recent 2 versions const maxVersionsRule = { rule: { - versions: 2, + maxVersions: 2, }, }; // Create a column family with given GC rule - [family] = await table.createFamily('cf2', maxVersionsRule); + [family] = await BigtableTableAdminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf2', + create: { + gcRule: GCRuleMaker.makeRule(maxVersionsRule), + }, + }, + ], + }); console.log(`Created column family ${family.id}`); // [END bigtable_create_family_gc_max_versions] @@ -111,17 +121,29 @@ async function runTableOperations(instanceID, tableID) { // Define a GC rule to drop cells older than 5 days or not the most recent version const unionRule = { + ruleType: 'union', rule: { - versions: 1, - age: { - seconds: 60 * 60 * 24 * 5, - nanos: 0, + maxVersions: 1, + rule: { + maxAge: { + seconds: 60 * 60 * 24 * 5, + nanos: 0, + }, }, - union: true, }, }; - [family] = await table.createFamily('cf3', unionRule); + [family] = await BigtableTableAdminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf3', + create: { + gcRule: GCRuleMaker.makeRule(unionRule), + }, + }, + ], + }); console.log(`Created column family ${family.id}`); // [END bigtable_create_family_gc_union] @@ -132,16 +154,28 @@ async function runTableOperations(instanceID, tableID) { // GC rule: Drop cells older than 5 days AND older than the most recent 2 versions const intersectionRule = { + ruleType: 'intersection', rule: { - versions: 2, - age: { - seconds: 60 * 60 * 24 * 5, - nanos: 0, + maxVersions: 2, + rule: { + maxAge: { + seconds: 60 * 60 * 24 * 5, + nanos: 0, + }, }, - intersection: true, }, }; - [family] = await table.createFamily('cf4', intersectionRule); + [family] = await BigtableTableAdminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf4', + create: { + gcRule: GCRuleMaker.makeRule(intersectionRule), + }, + }, + ], + }); console.log(`Created column family ${family.id}`); // [END bigtable_create_family_gc_intersection] @@ -153,19 +187,36 @@ async function runTableOperations(instanceID, tableID) { // OR // Drop cells that are older than a month AND older than the 2 recent versions const nestedRule = { - union: true, - versions: 10, + ruleType: 'union', rule: { - versions: 2, - age: { - // one month - seconds: 60 * 60 * 24 * 30, - nanos: 0, + maxVersions: 10, + rule: { + ruleType: 'intersection', + rule: { + maxVersions: 2, + rule: { + maxAge: { + // one month + seconds: 60 * 60 * 24 * 30, + nanos: 0, + }, + }, + }, }, }, }; - [family] = await table.createFamily('cf5', nestedRule); + [family] = await BigtableTableAdminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf5', + create: { + gcRule: GCRuleMaker.makeRule(nestedRule), + }, + }, + ], + }); console.log(`Created column family ${family.id}`); // [END bigtable_create_family_gc_nested] From d5abeb099503b3fadd69f1eaf67324e0e79a85fd Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 20 Aug 2025 19:08:42 +0000 Subject: [PATCH 04/96] feat: updated samples to use GCRuleMaker --- .../api-reference-doc-snippets/instance.js | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/samples/api-reference-doc-snippets/instance.js b/samples/api-reference-doc-snippets/instance.js index 5683ea94c..6f0b3f980 100644 --- a/samples/api-reference-doc-snippets/instance.js +++ b/samples/api-reference-doc-snippets/instance.js @@ -113,35 +113,53 @@ const snippets = { createTable: (instanceId, tableId) => { // [START bigtable_api_create_table] const {Bigtable} = require('@google-cloud/bigtable'); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const bigtable = new Bigtable(); const instance = bigtable.instance(instanceId); - - const options = { - families: ['follows'], + const adminClient = new BigtableTableAdminClient(); + + const request = { + parent: instance.name, + tableId: tableId, + table: { + columnFamilies: { + follows: {}, + }, + }, }; // You can also specify garbage collection rules for your column families. // See {@link Table#createFamily} for more information about // column families and garbage collection rules. //- - // const options = { - // families: [ - // { - // name: 'follows', - // rule: { - // age: { - // seconds: 0, - // nanos: 5000 + // const request = { + // parent: instance.name, + // tableId: tableId, + // table: { + // columnFamilies: { + // follows: { + // gcRule: { + // union: { + // rules: [ + // { + // maxAge: { + // seconds: 0, + // nanos: 5000, + // }, + // }, + // { + // maxNumVersions: 3, + // }, + // ], + // }, // }, - // versions: 3, - // union: true - // } - // } - // ] + // }, + // }, + // }, // }; - instance - .createTable(tableId, options) + adminClient + .createTable(request) .then(result => { const newTable = result[0]; // const apiResponse = result[1]; From 0e8d911e70413d0902729192257f29b1d6851db3 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 21 Aug 2025 15:50:20 +0000 Subject: [PATCH 05/96] feat: Update restoreTable sample to use generated client This commit updates the `backups.restore.js` sample to use the `BigtableTableAdminClient` directly for restoring a table from a backup, instead of going through the handwritten `bigtable.instance().createTableFromBackup()` method. This change is based on the design document for the Node.js Bigtable Admin API autogeneration. The corresponding test for the sample in `samples/test/backups.js` has also been updated to pass the correct arguments to the updated sample script. --- .../backups.restore.js | 26 +++++++++++++------ samples/test/backups.js | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/samples/api-reference-doc-snippets/backups.restore.js b/samples/api-reference-doc-snippets/backups.restore.js index 194a34353..bf13f90fb 100644 --- a/samples/api-reference-doc-snippets/backups.restore.js +++ b/samples/api-reference-doc-snippets/backups.restore.js @@ -15,11 +15,11 @@ async function main( instanceId = 'YOUR_INSTANCE_ID', tableId = 'YOUR_TABLE_ID', - backupId = 'YOUR_BACKUP_ID', + clusterId = 'YOUR_CLUSTER_ID', + backupId = 'YOUR_BACKUP_ID' ) { // [START bigtable_api_restore_backup] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; async function restoreBackup() { /** @@ -27,16 +27,26 @@ async function main( */ // const instanceId = 'YOUR_INSTANCE_ID'; // const tableId = 'YOUR_TABLE_ID'; + // const clusterId = 'YOUR_CLUSTER_ID'; // const backupId = 'YOUR_BACKUP_ID'; - const instance = bigtable.instance(instanceId); + + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); // Restore a table to an instance. - const [table, operation] = await instance.createTableFromBackup({ - table: tableId, - backup: backupId, + const [operation] = await adminClient.restoreTable({ + parent: adminClient.instancePath(projectId, instanceId), + tableId, + backup: adminClient.backupPath( + projectId, + instanceId, + clusterId, + backupId + ), }); - await operation.promise(); + const [table] = await operation.promise(); + console.log(`Table restored to ${table.id} successfully.`); } diff --git a/samples/test/backups.js b/samples/test/backups.js index 6eebbaf9f..7a1fc369a 100644 --- a/samples/test/backups.js +++ b/samples/test/backups.js @@ -140,7 +140,7 @@ describe('backups', async () => { it('should restore a backup', () => { const newTableId = generateId(); const stdout = execSync( - `node ./backups.list.js ${INSTANCE_ID} ${newTableId} ${BACKUP_ID}`, + `node ./backups.restore.js ${INSTANCE_ID} ${newTableId} ${CLUSTER_ID} ${BACKUP_ID}` ); assert.include(stdout, `Table restored to ${newTableId} successfully.`); }); From f6c20e93aa3a5ad3c19b64ca168dd27b70d08a8e Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 21 Aug 2025 14:02:19 -0400 Subject: [PATCH 06/96] table id to table name --- samples/api-reference-doc-snippets/backups.restore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/api-reference-doc-snippets/backups.restore.js b/samples/api-reference-doc-snippets/backups.restore.js index bf13f90fb..0305cc8ec 100644 --- a/samples/api-reference-doc-snippets/backups.restore.js +++ b/samples/api-reference-doc-snippets/backups.restore.js @@ -47,7 +47,7 @@ async function main( const [table] = await operation.promise(); - console.log(`Table restored to ${table.id} successfully.`); + console.log(`Table restored to ${table.name} successfully.`); } await restoreBackup(); From 23d186c422e4c6596ca236d7c7b23565546beb49 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 21 Aug 2025 15:25:27 -0400 Subject: [PATCH 07/96] The rule should be a union - not nested instance of the admin client should be used --- samples/api-reference-doc-snippets/table.js | 34 ++++++++++----------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/samples/api-reference-doc-snippets/table.js b/samples/api-reference-doc-snippets/table.js index 412b2ed6b..26a46f60a 100644 --- a/samples/api-reference-doc-snippets/table.js +++ b/samples/api-reference-doc-snippets/table.js @@ -91,28 +91,26 @@ const snippets = { // [START bigtable_api_create_family] const options = { ruleType: 'union', - rule: { - maxVersions: 3, - rule: { - maxAge: { - seconds: 0, - nanos: 5000, - }, - }, + maxVersions: 3, + maxAge: { + seconds: 0, + nanos: 5000, }, }; - BigtableTableAdminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: familyId, - create: { - gcRule: GCRuleMaker.makeRule(options), + const adminClient = new BigtableTableAdminClient(); + adminClient + .modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: familyId, + create: { + gcRule: GCRuleMaker.makeRule(options), + }, }, - }, - ], - }) + ], + }) .then(result => { const family = result[0]; // const apiResponse = result[1]; From b5c52d4a8315bd2476ec035047b156b298c499c1 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 21 Aug 2025 15:34:57 -0400 Subject: [PATCH 08/96] Use instance of admin client - not admin client itself --- samples/tableadmin.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/samples/tableadmin.js b/samples/tableadmin.js index 68f1059a4..8fc22af6e 100644 --- a/samples/tableadmin.js +++ b/samples/tableadmin.js @@ -15,6 +15,7 @@ // Imports the Google Cloud client library const {Bigtable, GCRuleMaker} = require('@google-cloud/bigtable'); const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; +const adminClient = new BigtableTableAdminClient(); async function runTableOperations(instanceID, tableID) { const bigtable = new Bigtable(); @@ -72,7 +73,7 @@ async function runTableOperations(instanceID, tableID) { }, }, }; - let [family] = await BigtableTableAdminClient.modifyColumnFamilies({ + let [family] = await adminClient.modifyColumnFamilies({ name: table.name, modifications: [ { @@ -100,7 +101,7 @@ async function runTableOperations(instanceID, tableID) { }; // Create a column family with given GC rule - [family] = await BigtableTableAdminClient.modifyColumnFamilies({ + [family] = await adminClient.modifyColumnFamilies({ name: table.name, modifications: [ { @@ -133,7 +134,7 @@ async function runTableOperations(instanceID, tableID) { }, }; - [family] = await BigtableTableAdminClient.modifyColumnFamilies({ + [family] = await adminClient.modifyColumnFamilies({ name: table.name, modifications: [ { @@ -165,7 +166,7 @@ async function runTableOperations(instanceID, tableID) { }, }, }; - [family] = await BigtableTableAdminClient.modifyColumnFamilies({ + [family] = await adminClient.modifyColumnFamilies({ name: table.name, modifications: [ { @@ -206,7 +207,7 @@ async function runTableOperations(instanceID, tableID) { }, }; - [family] = await BigtableTableAdminClient.modifyColumnFamilies({ + [family] = await adminClient.modifyColumnFamilies({ name: table.name, modifications: [ { From 541a6c067ed8f1727b2002062be06ed32b3c59e8 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 21 Aug 2025 15:49:09 -0400 Subject: [PATCH 09/96] =?UTF-8?q?Update=20the=20rules=20so=20they=20won?= =?UTF-8?q?=E2=80=99t=20throw=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samples/tableadmin.js | 44 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/samples/tableadmin.js b/samples/tableadmin.js index 8fc22af6e..585ba340a 100644 --- a/samples/tableadmin.js +++ b/samples/tableadmin.js @@ -123,14 +123,10 @@ async function runTableOperations(instanceID, tableID) { // Define a GC rule to drop cells older than 5 days or not the most recent version const unionRule = { ruleType: 'union', - rule: { - maxVersions: 1, - rule: { - maxAge: { - seconds: 60 * 60 * 24 * 5, - nanos: 0, - }, - }, + maxVersions: 1, + maxAge: { + seconds: 60 * 60 * 24 * 5, + nanos: 0, }, }; @@ -156,14 +152,10 @@ async function runTableOperations(instanceID, tableID) { // GC rule: Drop cells older than 5 days AND older than the most recent 2 versions const intersectionRule = { ruleType: 'intersection', - rule: { - maxVersions: 2, - rule: { - maxAge: { - seconds: 60 * 60 * 24 * 5, - nanos: 0, - }, - }, + maxVersions: 2, + maxAge: { + seconds: 60 * 60 * 24 * 5, + nanos: 0, }, }; [family] = await adminClient.modifyColumnFamilies({ @@ -189,20 +181,14 @@ async function runTableOperations(instanceID, tableID) { // Drop cells that are older than a month AND older than the 2 recent versions const nestedRule = { ruleType: 'union', + maxVersions: 10, rule: { - maxVersions: 10, - rule: { - ruleType: 'intersection', - rule: { - maxVersions: 2, - rule: { - maxAge: { - // one month - seconds: 60 * 60 * 24 * 30, - nanos: 0, - }, - }, - }, + ruleType: 'intersection', + maxVersions: 2, + maxAge: { + // one month + seconds: 60 * 60 * 24 * 30, + nanos: 0, }, }, }; From 06e875cf9d15d8bb655c4e01404aa2826c37cf3f Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 21 Aug 2025 15:53:12 -0400 Subject: [PATCH 10/96] change family.id to family.name --- samples/tableadmin.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/tableadmin.js b/samples/tableadmin.js index 585ba340a..da8149385 100644 --- a/samples/tableadmin.js +++ b/samples/tableadmin.js @@ -84,7 +84,7 @@ async function runTableOperations(instanceID, tableID) { }, ], }); - console.log(`Created column family ${family.id}`); + console.log(`Created column family ${family.name}`); // [END bigtable_create_family_gc_max_age] console.log(); @@ -112,7 +112,7 @@ async function runTableOperations(instanceID, tableID) { }, ], }); - console.log(`Created column family ${family.id}`); + console.log(`Created column family ${family.name}`); // [END bigtable_create_family_gc_max_versions] console.log(); @@ -141,7 +141,7 @@ async function runTableOperations(instanceID, tableID) { }, ], }); - console.log(`Created column family ${family.id}`); + console.log(`Created column family ${family.name}`); // [END bigtable_create_family_gc_union] console.log(); @@ -169,7 +169,7 @@ async function runTableOperations(instanceID, tableID) { }, ], }); - console.log(`Created column family ${family.id}`); + console.log(`Created column family ${family.name}`); // [END bigtable_create_family_gc_intersection] console.log(); @@ -204,7 +204,7 @@ async function runTableOperations(instanceID, tableID) { }, ], }); - console.log(`Created column family ${family.id}`); + console.log(`Created column family ${family.name}`); // [END bigtable_create_family_gc_nested] console.log(); From 36aa3edd17d497157f76f5bfbbc3535392306eb0 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 21 Aug 2025 16:46:13 -0400 Subject: [PATCH 11/96] max age has to be at least 1 millisecond --- samples/api-reference-doc-snippets/table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/api-reference-doc-snippets/table.js b/samples/api-reference-doc-snippets/table.js index 26a46f60a..a0a0955c5 100644 --- a/samples/api-reference-doc-snippets/table.js +++ b/samples/api-reference-doc-snippets/table.js @@ -93,7 +93,7 @@ const snippets = { ruleType: 'union', maxVersions: 3, maxAge: { - seconds: 0, + seconds: 1, nanos: 5000, }, }; From e80d55c0a5b90ab61d4364c669ba8455177707d7 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 21 Aug 2025 16:54:59 -0400 Subject: [PATCH 12/96] Run linter --- samples/api-reference-doc-snippets/backups.restore.js | 4 ++-- samples/test/backups.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/api-reference-doc-snippets/backups.restore.js b/samples/api-reference-doc-snippets/backups.restore.js index 0305cc8ec..530813683 100644 --- a/samples/api-reference-doc-snippets/backups.restore.js +++ b/samples/api-reference-doc-snippets/backups.restore.js @@ -16,7 +16,7 @@ async function main( instanceId = 'YOUR_INSTANCE_ID', tableId = 'YOUR_TABLE_ID', clusterId = 'YOUR_CLUSTER_ID', - backupId = 'YOUR_BACKUP_ID' + backupId = 'YOUR_BACKUP_ID', ) { // [START bigtable_api_restore_backup] const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; @@ -41,7 +41,7 @@ async function main( projectId, instanceId, clusterId, - backupId + backupId, ), }); diff --git a/samples/test/backups.js b/samples/test/backups.js index 7a1fc369a..b2bc3a862 100644 --- a/samples/test/backups.js +++ b/samples/test/backups.js @@ -140,7 +140,7 @@ describe('backups', async () => { it('should restore a backup', () => { const newTableId = generateId(); const stdout = execSync( - `node ./backups.restore.js ${INSTANCE_ID} ${newTableId} ${CLUSTER_ID} ${BACKUP_ID}` + `node ./backups.restore.js ${INSTANCE_ID} ${newTableId} ${CLUSTER_ID} ${BACKUP_ID}`, ); assert.include(stdout, `Table restored to ${newTableId} successfully.`); }); From e1ccefb2db8a55ecc680a43fdce12dae2edb9484 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 21 Aug 2025 16:58:59 -0400 Subject: [PATCH 13/96] Refresh project id token --- samples/tableadmin.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/samples/tableadmin.js b/samples/tableadmin.js index da8149385..58644be7e 100644 --- a/samples/tableadmin.js +++ b/samples/tableadmin.js @@ -19,6 +19,16 @@ const adminClient = new BigtableTableAdminClient(); async function runTableOperations(instanceID, tableID) { const bigtable = new Bigtable(); + const defaultProjectId = await new Promise((resolve, reject) => { + bigtable.getProjectId_((err, projectId) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + bigtable.projectName = `projects/${defaultProjectId}`; const instance = bigtable.instance(instanceID); const table = instance.table(tableID); From 178a0dfb6c40bd0df15a9f641cee5b4cd656efd4 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 21 Aug 2025 17:03:00 -0400 Subject: [PATCH 14/96] Get rid of projectId token --- samples/api-reference-doc-snippets/table.js | 13 ++++++++++++- samples/tableadmin.js | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/samples/api-reference-doc-snippets/table.js b/samples/api-reference-doc-snippets/table.js index a0a0955c5..69863b378 100644 --- a/samples/api-reference-doc-snippets/table.js +++ b/samples/api-reference-doc-snippets/table.js @@ -84,7 +84,18 @@ const snippets = { // [END bigtable_api_get_table_meta] }, - createFamily: (instanceId, tableId, familyId) => { + createFamily: async (instanceId, tableId, familyId) => { + // The request will only work if the projectName doesn't contain the {{projectId}} token. + const defaultProjectId = await new Promise((resolve, reject) => { + bigtable.getProjectId_((err, projectId) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + bigtable.projectName = `projects/${defaultProjectId}`; const instance = bigtable.instance(instanceId); const table = instance.table(tableId); diff --git a/samples/tableadmin.js b/samples/tableadmin.js index 58644be7e..ee80e5c5e 100644 --- a/samples/tableadmin.js +++ b/samples/tableadmin.js @@ -19,6 +19,7 @@ const adminClient = new BigtableTableAdminClient(); async function runTableOperations(instanceID, tableID) { const bigtable = new Bigtable(); + // The request will only work if the projectName doesn't contain the {{projectId}} token. const defaultProjectId = await new Promise((resolve, reject) => { bigtable.getProjectId_((err, projectId) => { if (err) { From c89320517746f2564db1a79ab69f139276c9f4f7 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Fri, 22 Aug 2025 11:03:21 -0400 Subject: [PATCH 15/96] revert change to backups method called --- samples/test/backups.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/test/backups.js b/samples/test/backups.js index b2bc3a862..2919b61f1 100644 --- a/samples/test/backups.js +++ b/samples/test/backups.js @@ -140,7 +140,7 @@ describe('backups', async () => { it('should restore a backup', () => { const newTableId = generateId(); const stdout = execSync( - `node ./backups.restore.js ${INSTANCE_ID} ${newTableId} ${CLUSTER_ID} ${BACKUP_ID}`, + `node ./backups.list.js ${INSTANCE_ID} ${newTableId} ${CLUSTER_ID} ${BACKUP_ID}`, ); assert.include(stdout, `Table restored to ${newTableId} successfully.`); }); From c749aa276fd911b62ccb73072e2d0e4abded967a Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Fri, 22 Aug 2025 11:06:04 -0400 Subject: [PATCH 16/96] Use the admin client for createTable instead --- samples/api-reference-doc-snippets/table.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/samples/api-reference-doc-snippets/table.js b/samples/api-reference-doc-snippets/table.js index 69863b378..48aab7526 100644 --- a/samples/api-reference-doc-snippets/table.js +++ b/samples/api-reference-doc-snippets/table.js @@ -18,12 +18,22 @@ const bigtable = new Bigtable(); const snippets = { createTable: (instanceId, tableId) => { + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); + const adminClient = new BigtableTableAdminClient(); + const request = { + parent: instance.name, + tableId: tableId, + table: { + columnFamilies: { + follows: {}, + }, + }, + }; // [START bigtable_api_create_table] - table - .create() + adminClient + .createTable(request) .then(result => { const table = result[0]; // let apiResponse = result[1]; From acd812f908a5599dc1bb772230b48db43ad41d91 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Fri, 22 Aug 2025 11:34:18 -0400 Subject: [PATCH 17/96] snippets should include admin client --- samples/api-reference-doc-snippets/instance.js | 12 +++++++++++- samples/api-reference-doc-snippets/table.js | 17 +++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/samples/api-reference-doc-snippets/instance.js b/samples/api-reference-doc-snippets/instance.js index 6f0b3f980..92345d25e 100644 --- a/samples/api-reference-doc-snippets/instance.js +++ b/samples/api-reference-doc-snippets/instance.js @@ -110,11 +110,21 @@ const snippets = { // [END bigtable_api_create_app_profile] }, - createTable: (instanceId, tableId) => { + createTable: async (instanceId, tableId) => { // [START bigtable_api_create_table] const {Bigtable} = require('@google-cloud/bigtable'); const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const bigtable = new Bigtable(); + const defaultProjectId = await new Promise((resolve, reject) => { + bigtable.getProjectId_((err, projectId) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + bigtable.projectName = `projects/${defaultProjectId}`; const instance = bigtable.instance(instanceId); const adminClient = new BigtableTableAdminClient(); diff --git a/samples/api-reference-doc-snippets/table.js b/samples/api-reference-doc-snippets/table.js index 48aab7526..fe11e8afe 100644 --- a/samples/api-reference-doc-snippets/table.js +++ b/samples/api-reference-doc-snippets/table.js @@ -13,12 +13,22 @@ // limitations under the License. const {Bigtable, GCRuleMaker} = require('@google-cloud/bigtable'); -const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const bigtable = new Bigtable(); const snippets = { - createTable: (instanceId, tableId) => { + createTable: async (instanceId, tableId) => { + // [START bigtable_api_create_table] const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const defaultProjectId = await new Promise((resolve, reject) => { + bigtable.getProjectId_((err, projectId) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + bigtable.projectName = `projects/${defaultProjectId}`; const instance = bigtable.instance(instanceId); const adminClient = new BigtableTableAdminClient(); const request = { @@ -30,8 +40,6 @@ const snippets = { }, }, }; - - // [START bigtable_api_create_table] adminClient .createTable(request) .then(result => { @@ -95,6 +103,7 @@ const snippets = { }, createFamily: async (instanceId, tableId, familyId) => { + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; // The request will only work if the projectName doesn't contain the {{projectId}} token. const defaultProjectId = await new Promise((resolve, reject) => { bigtable.getProjectId_((err, projectId) => { From 4ffd8753b2d1f344fe20ffdb5f60dd9151c3a070 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Fri, 22 Aug 2025 11:37:27 -0400 Subject: [PATCH 18/96] This code snippet should include project fetch --- samples/api-reference-doc-snippets/table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/api-reference-doc-snippets/table.js b/samples/api-reference-doc-snippets/table.js index fe11e8afe..88e756f52 100644 --- a/samples/api-reference-doc-snippets/table.js +++ b/samples/api-reference-doc-snippets/table.js @@ -103,6 +103,7 @@ const snippets = { }, createFamily: async (instanceId, tableId, familyId) => { + // [START bigtable_api_create_family] const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; // The request will only work if the projectName doesn't contain the {{projectId}} token. const defaultProjectId = await new Promise((resolve, reject) => { @@ -118,7 +119,6 @@ const snippets = { const instance = bigtable.instance(instanceId); const table = instance.table(tableId); - // [START bigtable_api_create_family] const options = { ruleType: 'union', maxVersions: 3, From eeb69f2f3ccce558b4b52319ab89a31cf81a7aac Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Fri, 22 Aug 2025 12:59:45 -0400 Subject: [PATCH 19/96] Comment out options --- samples/api-reference-doc-snippets/table.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/samples/api-reference-doc-snippets/table.js b/samples/api-reference-doc-snippets/table.js index 88e756f52..bc53fe0d7 100644 --- a/samples/api-reference-doc-snippets/table.js +++ b/samples/api-reference-doc-snippets/table.js @@ -119,14 +119,15 @@ const snippets = { const instance = bigtable.instance(instanceId); const table = instance.table(tableId); - const options = { - ruleType: 'union', - maxVersions: 3, - maxAge: { - seconds: 1, - nanos: 5000, - }, - }; + const options = {}; + // { + // ruleType: 'union', + // maxVersions: 3, + // maxAge: { + // seconds: 1, + // nanos: 5000, + // }, + // }; const adminClient = new BigtableTableAdminClient(); adminClient From a990f932b2cdca5f97ceead90a084fbde0a59c0c Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Fri, 22 Aug 2025 15:50:14 -0400 Subject: [PATCH 20/96] Use the admin client to create a table --- samples/tableadmin.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/samples/tableadmin.js b/samples/tableadmin.js index ee80e5c5e..dd132ca4a 100644 --- a/samples/tableadmin.js +++ b/samples/tableadmin.js @@ -40,7 +40,16 @@ async function runTableOperations(instanceID, tableID) { if (!tableExists) { // Create table if does not exist console.log(`Table does not exist. Creating table ${tableID}`); - await table.create(); + const request = { + parent: instance.name, + tableId: tableID, + table: { + columnFamilies: { + follows: {}, + }, + }, + }; + await adminClient.createTable(request); } else { console.log('Table exists.'); } From a69f533978416f8191b8e182b2875ad05d93c1cd Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Fri, 22 Aug 2025 16:19:04 -0400 Subject: [PATCH 21/96] Use the generated layer for maxVersions --- samples/hello-world/index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/samples/hello-world/index.js b/samples/hello-world/index.js index 9f1a8545e..2facea0d8 100644 --- a/samples/hello-world/index.js +++ b/samples/hello-world/index.js @@ -51,6 +51,8 @@ const getRowGreeting = row => { const [tableExists] = await table.exists(); if (!tableExists) { console.log(`Creating table ${TABLE_ID}`); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); const options = { families: [ { @@ -61,6 +63,19 @@ const getRowGreeting = row => { }, ], }; + await adminClient.createTable({ + parent: instance.name, + tableId: TABLE_ID, + table: { + columnFamilies: { + [COLUMN_FAMILY_ID]: { + gcRule: { + maxNumVersions: 1, + }, + }, + }, + }, + }); await table.create(options); } // [END bigtable_hw_create_table] From 577d0e30eef100c52d807b0e259d7ec7df260432 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Fri, 22 Aug 2025 16:47:18 -0400 Subject: [PATCH 22/96] =?UTF-8?q?Don=E2=80=99t=20use=20instance.name=20in?= =?UTF-8?q?=20parent=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samples/api-reference-doc-snippets/instance.js | 3 ++- samples/api-reference-doc-snippets/table.js | 3 ++- samples/hello-world/index.js | 2 +- samples/tableadmin.js | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/samples/api-reference-doc-snippets/instance.js b/samples/api-reference-doc-snippets/instance.js index 92345d25e..89f81c8ec 100644 --- a/samples/api-reference-doc-snippets/instance.js +++ b/samples/api-reference-doc-snippets/instance.js @@ -112,6 +112,7 @@ const snippets = { createTable: async (instanceId, tableId) => { // [START bigtable_api_create_table] + const projectId = 'projectId'; const {Bigtable} = require('@google-cloud/bigtable'); const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const bigtable = new Bigtable(); @@ -129,7 +130,7 @@ const snippets = { const adminClient = new BigtableTableAdminClient(); const request = { - parent: instance.name, + parent: adminClient.instancePath(projectId, instanceId), tableId: tableId, table: { columnFamilies: { diff --git a/samples/api-reference-doc-snippets/table.js b/samples/api-reference-doc-snippets/table.js index bc53fe0d7..57d844a4b 100644 --- a/samples/api-reference-doc-snippets/table.js +++ b/samples/api-reference-doc-snippets/table.js @@ -18,6 +18,7 @@ const bigtable = new Bigtable(); const snippets = { createTable: async (instanceId, tableId) => { // [START bigtable_api_create_table] + const projectId = 'projectId'; const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const defaultProjectId = await new Promise((resolve, reject) => { bigtable.getProjectId_((err, projectId) => { @@ -32,7 +33,7 @@ const snippets = { const instance = bigtable.instance(instanceId); const adminClient = new BigtableTableAdminClient(); const request = { - parent: instance.name, + parent: adminClient.instancePath(projectId, instanceId), tableId: tableId, table: { columnFamilies: { diff --git a/samples/hello-world/index.js b/samples/hello-world/index.js index 2facea0d8..083fda6f7 100644 --- a/samples/hello-world/index.js +++ b/samples/hello-world/index.js @@ -64,7 +64,7 @@ const getRowGreeting = row => { ], }; await adminClient.createTable({ - parent: instance.name, + parent: adminClient.instancePath('projectId', INSTANCE_ID), tableId: TABLE_ID, table: { columnFamilies: { diff --git a/samples/tableadmin.js b/samples/tableadmin.js index dd132ca4a..db971383c 100644 --- a/samples/tableadmin.js +++ b/samples/tableadmin.js @@ -19,6 +19,7 @@ const adminClient = new BigtableTableAdminClient(); async function runTableOperations(instanceID, tableID) { const bigtable = new Bigtable(); + const projectId = 'projectId'; // The request will only work if the projectName doesn't contain the {{projectId}} token. const defaultProjectId = await new Promise((resolve, reject) => { bigtable.getProjectId_((err, projectId) => { @@ -41,7 +42,7 @@ async function runTableOperations(instanceID, tableID) { // Create table if does not exist console.log(`Table does not exist. Creating table ${tableID}`); const request = { - parent: instance.name, + parent: adminClient.instancePath(projectId, instanceID), tableId: tableID, table: { columnFamilies: { From 1d50752caa0daf58c001b495b893f9ae43f08cdf Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Mon, 25 Aug 2025 10:29:10 -0400 Subject: [PATCH 23/96] Update the family snippets --- samples/test/family.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/samples/test/family.js b/samples/test/family.js index fcebcd576..96a58e67c 100644 --- a/samples/test/family.js +++ b/samples/test/family.js @@ -19,6 +19,7 @@ const {describe, it, before, after} = require('mocha'); const {Bigtable} = require('@google-cloud/bigtable'); const bigtable = new Bigtable(); +const projectId = 'projectId'; const INSTANCE_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules const CLUSTER_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules const TABLE_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules @@ -31,6 +32,7 @@ const instance = bigtable.instance(INSTANCE_ID); describe.skip('Family Snippets', () => { before(async () => { try { + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const [, operation] = await instance.create({ clusters: [ { @@ -42,7 +44,17 @@ describe.skip('Family Snippets', () => { type: 'DEVELOPMENT', }); await operation.promise(); - await instance.createTable(TABLE_ID); + const adminClient = new BigtableTableAdminClient(); + const request = { + parent: adminClient.instancePath(projectId, INSTANCE_ID), + tableId: TABLE_ID, + table: { + columnFamilies: { + [FAMILY_ID]: {}, + }, + }, + }; + await adminClient.createTable(request); } catch (err) { // } From 9994a100860e7118e68766bc0637409f1881bced Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Mon, 25 Aug 2025 10:33:22 -0400 Subject: [PATCH 24/96] Update createTable in the Row samples --- samples/test/row.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/samples/test/row.js b/samples/test/row.js index 251d1fe90..e15f7c7c4 100644 --- a/samples/test/row.js +++ b/samples/test/row.js @@ -22,6 +22,7 @@ const bigtable = new Bigtable(); const INSTANCE_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules const CLUSTER_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules const TABLE_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules +const PROJECT_ID = 'project-id'; const rowSnippets = require('./row.js'); @@ -30,6 +31,7 @@ const instance = bigtable.instance(INSTANCE_ID); describe.skip('Row Snippets', () => { before(async () => { try { + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const [, operation] = await instance.create({ clusters: [ { @@ -41,7 +43,13 @@ describe.skip('Row Snippets', () => { type: 'DEVELOPMENT', }); await operation.promise(); - await instance.createTable(TABLE_ID); + const adminClient = new BigtableTableAdminClient(); + const request = { + parent: adminClient.instancePath(PROJECT_ID, INSTANCE_ID), + tableId: TABLE_ID, + table: {}, + }; + await adminClient.createTable(request); } catch (err) { // Handle the error. } From 5abe9771969788306dc98253bc25dda96a0958e4 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Mon, 25 Aug 2025 10:52:04 -0400 Subject: [PATCH 25/96] Eliminate the need for any default projectId fetch --- .../api-reference-doc-snippets/instance.js | 13 --------- samples/api-reference-doc-snippets/table.js | 27 ++----------------- samples/tableadmin.js | 11 +------- 3 files changed, 3 insertions(+), 48 deletions(-) diff --git a/samples/api-reference-doc-snippets/instance.js b/samples/api-reference-doc-snippets/instance.js index 89f81c8ec..f97182f7c 100644 --- a/samples/api-reference-doc-snippets/instance.js +++ b/samples/api-reference-doc-snippets/instance.js @@ -113,20 +113,7 @@ const snippets = { createTable: async (instanceId, tableId) => { // [START bigtable_api_create_table] const projectId = 'projectId'; - const {Bigtable} = require('@google-cloud/bigtable'); const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; - const bigtable = new Bigtable(); - const defaultProjectId = await new Promise((resolve, reject) => { - bigtable.getProjectId_((err, projectId) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } - }); - }); - bigtable.projectName = `projects/${defaultProjectId}`; - const instance = bigtable.instance(instanceId); const adminClient = new BigtableTableAdminClient(); const request = { diff --git a/samples/api-reference-doc-snippets/table.js b/samples/api-reference-doc-snippets/table.js index 57d844a4b..1fba3f4f2 100644 --- a/samples/api-reference-doc-snippets/table.js +++ b/samples/api-reference-doc-snippets/table.js @@ -20,17 +20,6 @@ const snippets = { // [START bigtable_api_create_table] const projectId = 'projectId'; const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; - const defaultProjectId = await new Promise((resolve, reject) => { - bigtable.getProjectId_((err, projectId) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } - }); - }); - bigtable.projectName = `projects/${defaultProjectId}`; - const instance = bigtable.instance(instanceId); const adminClient = new BigtableTableAdminClient(); const request = { parent: adminClient.instancePath(projectId, instanceId), @@ -105,21 +94,9 @@ const snippets = { createFamily: async (instanceId, tableId, familyId) => { // [START bigtable_api_create_family] + const projectId = 'project-id'; const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; // The request will only work if the projectName doesn't contain the {{projectId}} token. - const defaultProjectId = await new Promise((resolve, reject) => { - bigtable.getProjectId_((err, projectId) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } - }); - }); - bigtable.projectName = `projects/${defaultProjectId}`; - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); - const options = {}; // { // ruleType: 'union', @@ -133,7 +110,7 @@ const snippets = { const adminClient = new BigtableTableAdminClient(); adminClient .modifyColumnFamilies({ - name: table.name, + name: adminClient.tablePath(projectId, instanceId, tableId), modifications: [ { id: familyId, diff --git a/samples/tableadmin.js b/samples/tableadmin.js index db971383c..2d63cc671 100644 --- a/samples/tableadmin.js +++ b/samples/tableadmin.js @@ -21,16 +21,7 @@ async function runTableOperations(instanceID, tableID) { const bigtable = new Bigtable(); const projectId = 'projectId'; // The request will only work if the projectName doesn't contain the {{projectId}} token. - const defaultProjectId = await new Promise((resolve, reject) => { - bigtable.getProjectId_((err, projectId) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } - }); - }); - bigtable.projectName = `projects/${defaultProjectId}`; + bigtable.projectName = `projects/${projectId}`; const instance = bigtable.instance(instanceID); const table = instance.table(tableID); From 6b559ae41c52b960579d0ca4f4e0c9fbfde4233e Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Mon, 25 Aug 2025 12:57:27 -0400 Subject: [PATCH 26/96] =?UTF-8?q?Don=E2=80=99t=20hardcode=20the=20project?= =?UTF-8?q?=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samples/api-reference-doc-snippets/instance.js | 2 +- samples/api-reference-doc-snippets/table.js | 8 ++++---- samples/hello-world/index.js | 3 ++- samples/tableadmin.js | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/samples/api-reference-doc-snippets/instance.js b/samples/api-reference-doc-snippets/instance.js index f97182f7c..8ba81e61b 100644 --- a/samples/api-reference-doc-snippets/instance.js +++ b/samples/api-reference-doc-snippets/instance.js @@ -112,9 +112,9 @@ const snippets = { createTable: async (instanceId, tableId) => { // [START bigtable_api_create_table] - const projectId = 'projectId'; const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); const request = { parent: adminClient.instancePath(projectId, instanceId), diff --git a/samples/api-reference-doc-snippets/table.js b/samples/api-reference-doc-snippets/table.js index 1fba3f4f2..75b66dba8 100644 --- a/samples/api-reference-doc-snippets/table.js +++ b/samples/api-reference-doc-snippets/table.js @@ -18,9 +18,9 @@ const bigtable = new Bigtable(); const snippets = { createTable: async (instanceId, tableId) => { // [START bigtable_api_create_table] - const projectId = 'projectId'; const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); const request = { parent: adminClient.instancePath(projectId, instanceId), tableId: tableId, @@ -94,8 +94,9 @@ const snippets = { createFamily: async (instanceId, tableId, familyId) => { // [START bigtable_api_create_family] - const projectId = 'project-id'; const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); // The request will only work if the projectName doesn't contain the {{projectId}} token. const options = {}; // { @@ -107,7 +108,6 @@ const snippets = { // }, // }; - const adminClient = new BigtableTableAdminClient(); adminClient .modifyColumnFamilies({ name: adminClient.tablePath(projectId, instanceId, tableId), @@ -412,4 +412,4 @@ const snippets = { }, }; -module.exports = snippets; +module.exports = snippets; \ No newline at end of file diff --git a/samples/hello-world/index.js b/samples/hello-world/index.js index 083fda6f7..fc2f3f2c8 100644 --- a/samples/hello-world/index.js +++ b/samples/hello-world/index.js @@ -63,8 +63,9 @@ const getRowGreeting = row => { }, ], }; + const projectId = await adminClient.getProjectId(); await adminClient.createTable({ - parent: adminClient.instancePath('projectId', INSTANCE_ID), + parent: adminClient.instancePath(projectId, INSTANCE_ID), tableId: TABLE_ID, table: { columnFamilies: { diff --git a/samples/tableadmin.js b/samples/tableadmin.js index 2d63cc671..df29d1353 100644 --- a/samples/tableadmin.js +++ b/samples/tableadmin.js @@ -19,7 +19,7 @@ const adminClient = new BigtableTableAdminClient(); async function runTableOperations(instanceID, tableID) { const bigtable = new Bigtable(); - const projectId = 'projectId'; + const projectId = await adminClient.getProjectId(); // The request will only work if the projectName doesn't contain the {{projectId}} token. bigtable.projectName = `projects/${projectId}`; const instance = bigtable.instance(instanceID); From 003ce8b3c4c0bee35bbe94a336cbb933f0c45497 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Mon, 25 Aug 2025 13:03:00 -0400 Subject: [PATCH 27/96] =?UTF-8?q?don=E2=80=99t=20hardcode=20project=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samples/test/family.js | 2 +- samples/test/row.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/test/family.js b/samples/test/family.js index 96a58e67c..24811a458 100644 --- a/samples/test/family.js +++ b/samples/test/family.js @@ -19,7 +19,6 @@ const {describe, it, before, after} = require('mocha'); const {Bigtable} = require('@google-cloud/bigtable'); const bigtable = new Bigtable(); -const projectId = 'projectId'; const INSTANCE_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules const CLUSTER_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules const TABLE_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules @@ -45,6 +44,7 @@ describe.skip('Family Snippets', () => { }); await operation.promise(); const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); const request = { parent: adminClient.instancePath(projectId, INSTANCE_ID), tableId: TABLE_ID, diff --git a/samples/test/row.js b/samples/test/row.js index e15f7c7c4..96e954fb3 100644 --- a/samples/test/row.js +++ b/samples/test/row.js @@ -22,7 +22,6 @@ const bigtable = new Bigtable(); const INSTANCE_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules const CLUSTER_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules const TABLE_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules -const PROJECT_ID = 'project-id'; const rowSnippets = require('./row.js'); @@ -44,8 +43,9 @@ describe.skip('Row Snippets', () => { }); await operation.promise(); const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); const request = { - parent: adminClient.instancePath(PROJECT_ID, INSTANCE_ID), + parent: adminClient.instancePath(projectId, INSTANCE_ID), tableId: TABLE_ID, table: {}, }; From 664afb7fddb282aeb55ff57b37dbcd526a3c04fa Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Mon, 25 Aug 2025 13:24:24 -0400 Subject: [PATCH 28/96] commit examples --- samples/examples/hello-world.js | 146 ++++++++++ samples/examples/instance-create-table.js | 30 ++ samples/examples/table-admin.js | 317 ++++++++++++++++++++++ samples/examples/table-create-family.js | 31 +++ 4 files changed, 524 insertions(+) create mode 100644 samples/examples/hello-world.js create mode 100644 samples/examples/instance-create-table.js create mode 100644 samples/examples/table-admin.js create mode 100644 samples/examples/table-create-family.js diff --git a/samples/examples/hello-world.js b/samples/examples/hello-world.js new file mode 100644 index 000000000..478d0aece --- /dev/null +++ b/samples/examples/hello-world.js @@ -0,0 +1,146 @@ +// Copyright 2018 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. + +/** + * A minimal application that demonstrates using the Nodejs Google Cloud API + * to connect to and interact with Cloud Bigtable. See + * https://github.com/googleapis/nodejs-bigtable/blob/master/samples/hello-world/README.md + * for more details + */ + +// This file will only work on node v8.x since it uses async/await. +// A version of this script is available for node v6.x in index.v6.js + +// [START bigtable_hw_imports] +const {Bigtable} = require('@google-cloud/bigtable'); +// [END bigtable_hw_imports] + +const TABLE_ID = 'Hello-Bigtable'; +const COLUMN_FAMILY_ID = 'cf1'; +const COLUMN_QUALIFIER = 'greeting'; +const INSTANCE_ID = process.env.INSTANCE_ID; + +if (!INSTANCE_ID) { + throw new Error('Environment variables for INSTANCE_ID must be set!'); +} + +const getRowGreeting = row => { + return row.data[COLUMN_FAMILY_ID][COLUMN_QUALIFIER][0].value; +}; + +(async () => { + try { + // [START bigtable_hw_connect] + const bigtableClient = new Bigtable(); + const instance = bigtableClient.instance(INSTANCE_ID); + // [END bigtable_hw_connect] + + // [START bigtable_hw_create_table] + const table = instance.table(TABLE_ID); + const [tableExists] = await table.exists(); + if (!tableExists) { + console.log(`Creating table ${TABLE_ID}`); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const options = { + families: [ + { + name: COLUMN_FAMILY_ID, + rule: { + versions: 1, + }, + }, + ], + }; + await adminClient.createTable({ + parent: adminClient.instancePath(projectId, INSTANCE_ID), + tableId: TABLE_ID, + table: { + columnFamilies: { + [COLUMN_FAMILY_ID]: { + gcRule: { + maxNumVersions: 1, + }, + }, + }, + }, + }); + await table.create(options); + } + // [END bigtable_hw_create_table] + + // [START bigtable_hw_write_rows] + console.log('Write some greetings to the table'); + const greetings = ['Hello World!', 'Hello Bigtable!', 'Hello Node!']; + const rowsToInsert = greetings.map((greeting, index) => ({ + // Note: This example uses sequential numeric IDs for simplicity, but this + // pattern can result in poor performance in a production application. + // Rows are stored in sorted order by key, so sequential keys can result + // in poor distribution of operations across nodes. + // + // For more information about how to design an effective schema for Cloud + // Bigtable, see the documentation: + // https://cloud.google.com/bigtable/docs/schema-design + key: `greeting${index}`, + data: { + [COLUMN_FAMILY_ID]: { + [COLUMN_QUALIFIER]: { + // Setting the timestamp allows the client to perform retries. If + // server-side time is used, retries may cause multiple cells to + // be generated. + timestamp: new Date(), + value: greeting, + }, + }, + }, + })); + await table.insert(rowsToInsert); + // [END bigtable_hw_write_rows] + + // [START bigtable_hw_create_filter] + const filter = [ + { + column: { + cellLimit: 1, // Only retrieve the most recent version of the cell. + }, + }, + ]; + // [END bigtable_hw_create_filter] + + // [START bigtable_hw_get_with_filter] + console.log('Reading a single row by row key'); + const [singleRow] = await table.row('greeting0').get({filter}); + console.log(` Read: ${getRowGreeting(singleRow)}`); + // [END bigtable_hw_get_with_filter] + + // [START bigtable_hw_scan_with_filter] + console.log('Reading the entire table'); + // Note: For improved performance in production applications, call + // `Table#readStream` to get a stream of rows. See the API documentation: + // https://cloud.google.com/nodejs/docs/reference/bigtable/latest/Table#createReadStream + const [allRows] = await table.getRows({filter}); + for (const row of allRows) { + console.log(` Read: ${getRowGreeting(row)}`); + } + // [END bigtable_hw_scan_with_filter] + + // [START bigtable_hw_delete_table] + console.log('Delete the table'); + await table.delete(); + // [END bigtable_hw_delete_table] + } catch (error) { + console.error('Something went wrong:', error); + } +})(); diff --git a/samples/examples/instance-create-table.js b/samples/examples/instance-create-table.js new file mode 100644 index 000000000..e50db0447 --- /dev/null +++ b/samples/examples/instance-create-table.js @@ -0,0 +1,30 @@ +async function main(instanceId = 'YOUR_INSTANCE_ID', tableId = 'YOUR_TABLE_ID') { + // [START bigtable_api_create_table] + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + + const request = { + parent: adminClient.instancePath(projectId, instanceId), + tableId: tableId, + table: { + columnFamilies: { + follows: {}, + }, + }, + }; + + adminClient + .createTable(request) + .then(result => { + const newTable = result[0]; + console.log(`Table ${newTable.name} created successfully.`); + }) + .catch(err => { + console.error(err); + }); + // [END bigtable_api_create_table] +} + +const args = process.argv.slice(2); +main(...args).catch(console.error); diff --git a/samples/examples/table-admin.js b/samples/examples/table-admin.js new file mode 100644 index 000000000..f68bb075c --- /dev/null +++ b/samples/examples/table-admin.js @@ -0,0 +1,317 @@ +// Copyright 2018 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. + +// Imports the Google Cloud client library +const {Bigtable, GCRuleMaker} = require('@google-cloud/bigtable'); +const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; +const adminClient = new BigtableTableAdminClient(); + +async function runTableOperations(instanceID, tableID) { + const bigtable = new Bigtable(); + const projectId = await adminClient.getProjectId(); + // The request will only work if the projectName doesn't contain the {{projectId}} token. + bigtable.projectName = `projects/${projectId}`; + const instance = bigtable.instance(instanceID); + const table = instance.table(tableID); + + // Check if table exists + console.log(); + console.log('Checking if table exists...'); + const [tableExists] = await table.exists(); + if (!tableExists) { + // Create table if does not exist + console.log(`Table does not exist. Creating table ${tableID}`); + const request = { + parent: adminClient.instancePath(projectId, instanceID), + tableId: tableID, + table: { + columnFamilies: { + follows: {}, + }, + }, + }; + await adminClient.createTable(request); + } else { + console.log('Table exists.'); + } + + console.log(); + console.log('Listing tables in current project...'); + // [START bigtable_list_tables] + // List tables in current project + const [tables] = await instance.getTables(); + tables.forEach(table => { + console.log(table.id); + }); + // [END bigtable_list_tables] + + console.log(); + console.log('Printing table metadata...'); + // [START bigtable_get_table_metadata] + // Get table metadata, and apply a view to the table fields + // Supported views include ID, schema or full + // View defaults to schema if unspecified. + const options = { + view: 'id', + }; + const [tableMetadata] = await table.getMetadata(options); + console.log(`Metadata: ${JSON.stringify(tableMetadata)}`); + // [END bigtable_get_table_metadata] + + console.log(); + console.log('Creating column family cf1 with max age GC rule...'); + // [START bigtable_create_family_gc_max_age] + // Create a column family with GC policy : maximum age + // where age = current time minus cell timestamp + + // Define the GC rule to retain data with max age of 5 days + const maxAgeRule = { + rule: { + maxAge: { + // Value must be atleast 1 millisecond + seconds: 60 * 60 * 24 * 5, + nanos: 0, + }, + }, + }; + let [family] = await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf1', + create: { + gcRule: GCRuleMaker.makeRule(maxAgeRule), + }, + }, + ], + }); + console.log(`Created column family ${family.name}`); + // [END bigtable_create_family_gc_max_age] + + console.log(); + console.log('Creating column family cf2 with max versions GC rule...'); + // [START bigtable_create_family_gc_max_versions] + // Create a column family with GC policy : most recent N versions + // where 1 = most recent version + + // Define the GC policy to retain only the most recent 2 versions + const maxVersionsRule = { + rule: { + maxVersions: 2, + }, + }; + + // Create a column family with given GC rule + [family] = await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf2', + create: { + gcRule: GCRuleMaker.makeRule(maxVersionsRule), + }, + }, + ], + }); + console.log(`Created column family ${family.name}`); + // [END bigtable_create_family_gc_max_versions] + + console.log(); + console.log('Creating column family cf3 with union GC rule...'); + // [START bigtable_create_family_gc_union] + // Create a column family with GC policy to drop data that matches at least one condition. + + // Define a GC rule to drop cells older than 5 days or not the most recent version + const unionRule = { + ruleType: 'union', + maxVersions: 1, + maxAge: { + seconds: 60 * 60 * 24 * 5, + nanos: 0, + }, + }; + + [family] = await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf3', + create: { + gcRule: GCRuleMaker.makeRule(unionRule), + }, + }, + ], + }); + console.log(`Created column family ${family.name}`); + // [END bigtable_create_family_gc_union] + + console.log(); + console.log('Creating column family cf4 with intersect GC rule...'); + // [START bigtable_create_family_gc_intersection] + // Create a column family with GC policy to drop data that matches all conditions + + // GC rule: Drop cells older than 5 days AND older than the most recent 2 versions + const intersectionRule = { + ruleType: 'intersection', + maxVersions: 2, + maxAge: { + seconds: 60 * 60 * 24 * 5, + nanos: 0, + }, + }; + [family] = await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf4', + create: { + gcRule: GCRuleMaker.makeRule(intersectionRule), + }, + }, + ], + }); + console.log(`Created column family ${family.name}`); + // [END bigtable_create_family_gc_intersection] + + console.log(); + console.log('Creating column family cf5 with a nested GC rule...'); + // [START bigtable_create_family_gc_nested] + // Create a nested GC rule: + // Drop cells that are either older than the 10 recent versions + // OR + // Drop cells that are older than a month AND older than the 2 recent versions + const nestedRule = { + ruleType: 'union', + maxVersions: 10, + rule: { + ruleType: 'intersection', + maxVersions: 2, + maxAge: { + // one month + seconds: 60 * 60 * 24 * 30, + nanos: 0, + }, + }, + }; + + [family] = await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf5', + create: { + gcRule: GCRuleMaker.makeRule(nestedRule), + }, + }, + ], + }); + console.log(`Created column family ${family.name}`); + // [END bigtable_create_family_gc_nested] + + console.log(); + console.log('Printing ID and GC Rule for all column families...'); + // [START bigtable_list_column_families] + // List all families in the table with GC rules + const [families] = await table.getFamilies(); + // Print ID, GC Rule for each column family + families.forEach(family => { + const metadata = JSON.stringify(family.metadata); + console.log(`Column family: ${family.id}, Metadata: ${metadata}`); + /* Sample output: + Column family: projects/{{projectId}}/instances/my-instance/tables/my-table/columnFamilies/cf4, + Metadata: {"gcRule":{"intersection":{"rules":[{"maxAge":{"seconds":"432000","nanos":0},"rule":"maxAge"},{"maxNumVersions":2,"rule":"maxNumVersions"}]},"rule":"intersection"}} + */ + }); + // [END bigtable_list_column_families] + + console.log('\nUpdating column family cf1 GC rule...'); + // [START bigtable_update_gc_rule] + // Update the column family metadata to update the GC rule + + // Create a reference to the column family + family = table.family('cf1'); + + // Update a column family GC rule + const updatedMetadata = { + rule: { + versions: 1, + }, + }; + + const [apiResponse] = await family.setMetadata(updatedMetadata); + console.log(`Updated GC rule: ${JSON.stringify(apiResponse)}`); + // [END bigtable_update_gc_rule] + + console.log('\nPrint updated column family cf1 GC rule...'); + // [START bigtable_family_get_gc_rule] + // Retrieve column family metadata (Id, column family GC rule) + const [metadata] = await family.getMetadata(); + console.log(`Metadata: ${JSON.stringify(metadata)}`); + // [END bigtable_family_get_gc_rule] + + console.log('\nDelete a column family cf2...'); + // [START bigtable_delete_family] + // Delete a column family + await family.delete(); + console.log(`${family.id} deleted successfully\n`); + // [END bigtable_delete_family] + console.log( + 'Run node $0 delete --instance [instanceID] --table [tableID] to delete the table.\n', + ); +} + +async function deleteTable(instanceID, tableID) { + // const instanceID = "my-instance"; + // const tableID = "my-bigtable-ID"; + const bigtableClient = new Bigtable(); + const instance = bigtableClient.instance(instanceID); + const table = instance.table(tableID); + // [START bigtable_delete_table] + // Delete the entire table + console.log('Delete the table.'); + await table.delete(); + console.log(`Table deleted: ${table.id}`); + // [END bigtable_delete_table] +} + +require('yargs') + .demand(1) + .command( + 'run', + 'Create a table (if does not exist) and run basic table operations.', + {}, + argv => runTableOperations(argv.instance, argv.table), + ) + .example( + 'node $0 run --instance [instanceID] --table [tableID]', + 'Create a table (if does not exist) and run basic table operations.', + ) + .wrap(120) + .command('delete', 'Delete table.', {}, + argv => deleteTable(argv.instance, argv.table), + ) + .example( + 'node $0 delete --instance [instanceID] --table [tableID]', + 'Delete a table.', + ) + .wrap(120) + .nargs('instance', 1) + .nargs('table', 1) + .describe('instance', 'Cloud Bigtable Instance ID') + .describe('table', 'Cloud Bigtable Table ID') + .demandOption(['instance', 'table']) + .recommendCommands() + .epilogue('For more information, see https://cloud.google.com/bigtable/docs') + .help() + .strict().argv; diff --git a/samples/examples/table-create-family.js b/samples/examples/table-create-family.js new file mode 100644 index 000000000..a6ead80cd --- /dev/null +++ b/samples/examples/table-create-family.js @@ -0,0 +1,31 @@ +async function main(instanceId = 'YOUR_INSTANCE_ID', tableId = 'YOUR_TABLE_ID', familyId = 'YOUR_FAMILY_ID') { + // [START bigtable_api_create_family] + const {BigtableTableAdminClient, GCRuleMaker} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const options = {}; + + adminClient + .modifyColumnFamilies({ + name: adminClient.tablePath(projectId, instanceId, tableId), + modifications: [ + { + id: familyId, + create: { + gcRule: GCRuleMaker.makeRule(options), + }, + }, + ], + }) + .then(result => { + const family = result[0]; + console.log(`Family ${family.name} created successfully.`); + }) + .catch(err => { + console.error(err); + }); + // [END bigtable_api_create_family] +} + +const args = process.argv.slice(2); +main(...args).catch(console.error); From f966e7795c7f21c30affffcb076078ec31e90f06 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Mon, 25 Aug 2025 13:31:06 -0400 Subject: [PATCH 29/96] =?UTF-8?q?Don=E2=80=99t=20create=20table=20twice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samples/examples/hello-world.js | 1 - samples/hello-world/index.js | 1 - 2 files changed, 2 deletions(-) diff --git a/samples/examples/hello-world.js b/samples/examples/hello-world.js index 478d0aece..bdd067425 100644 --- a/samples/examples/hello-world.js +++ b/samples/examples/hello-world.js @@ -77,7 +77,6 @@ const getRowGreeting = row => { }, }, }); - await table.create(options); } // [END bigtable_hw_create_table] diff --git a/samples/hello-world/index.js b/samples/hello-world/index.js index fc2f3f2c8..37c78178f 100644 --- a/samples/hello-world/index.js +++ b/samples/hello-world/index.js @@ -77,7 +77,6 @@ const getRowGreeting = row => { }, }, }); - await table.create(options); } // [END bigtable_hw_create_table] From acaf7e99b635d18a66f9568f341525c47bfc9327 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Mon, 25 Aug 2025 13:31:46 -0400 Subject: [PATCH 30/96] options is not used. remove it --- samples/examples/hello-world.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/samples/examples/hello-world.js b/samples/examples/hello-world.js index bdd067425..cd2f20364 100644 --- a/samples/examples/hello-world.js +++ b/samples/examples/hello-world.js @@ -54,16 +54,6 @@ const getRowGreeting = row => { const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); - const options = { - families: [ - { - name: COLUMN_FAMILY_ID, - rule: { - versions: 1, - }, - }, - ], - }; await adminClient.createTable({ parent: adminClient.instancePath(projectId, INSTANCE_ID), tableId: TABLE_ID, From c901c0a509396407d507a6a0570bbab8579c06e1 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Mon, 25 Aug 2025 14:15:49 -0400 Subject: [PATCH 31/96] table admin --- samples/samples-again/table-admin.js | 288 +++++++++++++++++++++++++++ 1 file changed, 288 insertions(+) create mode 100644 samples/samples-again/table-admin.js diff --git a/samples/samples-again/table-admin.js b/samples/samples-again/table-admin.js new file mode 100644 index 000000000..0ffe4bc49 --- /dev/null +++ b/samples/samples-again/table-admin.js @@ -0,0 +1,288 @@ +// Copyright 2018 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. + +// Imports the Google Cloud client library +const {Bigtable, GCRuleMaker} = require('@google-cloud/bigtable'); +const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; +const adminClient = new BigtableTableAdminClient(); + +async function runTableOperations(instanceID, tableID) { + const bigtable = new Bigtable(); + const projectId = await adminClient.getProjectId(); + // The request will only work if the projectName doesn't contain the {{projectId}} token. + bigtable.projectName = `projects/${projectId}`; + const instance = bigtable.instance(instanceID); + const table = instance.table(tableID); + + // Check if table exists + console.log(); + console.log('Checking if table exists...'); + const [tableExists] = await table.exists(); + if (!tableExists) { + // Create table if does not exist + console.log(`Table does not exist. Creating table ${tableID}`); + const request = { + parent: adminClient.instancePath(projectId, instanceID), + tableId: tableID, + table: { + columnFamilies: { + follows: {}, + }, + }, + }; + await adminClient.createTable(request); + } else { + console.log('Table exists.'); + } + + console.log(); + console.log('Listing tables in current project...'); + // [START bigtable_list_tables] + // List tables in current project + const [tables] = await instance.getTables(); + tables.forEach(table => { + console.log(table.id); + }); + // [END bigtable_list_tables] + + console.log(); + console.log('Printing table metadata...'); + // [START bigtable_get_table_metadata] + // Get table metadata, and apply a view to the table fields + // Supported views include ID, schema or full + // View defaults to schema if unspecified. + const options = { + view: 'id', + }; + const [tableMetadata] = await table.getMetadata(options); + console.log(`Metadata: ${JSON.stringify(tableMetadata)}`); + // [END bigtable_get_table_metadata] + + console.log(); + console.log('Creating column family cf1 with max age GC rule...'); + // [START bigtable_create_family_gc_max_age] + // Create a column family with GC policy : maximum age + // where age = current time minus cell timestamp + + // Define the GC rule to retain data with max age of 5 days + const maxAgeRule = { + rule: { + maxAge: { + // Value must be atleast 1 millisecond + seconds: 60 * 60 * 24 * 5, + nanos: 0, + }, + }, + }; + let [family] = await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf1', + create: { + gcRule: GCRuleMaker.makeRule(maxAgeRule), + }, + }, + ], + }); + console.log(`Created column family ${family.name}`); + // [END bigtable_create_family_gc_max_age] + + console.log(); + console.log('Creating column family cf2 with max versions GC rule...'); + // [START bigtable_create_family_gc_max_versions] + // Create a column family with GC policy : most recent N versions + // where 1 = most recent version + + // Define the GC policy to retain only the most recent 2 versions + const maxVersionsRule = { + rule: { + maxVersions: 2, + }, + }; + + // Create a column family with given GC rule + [family] = await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf2', + create: { + gcRule: GCRuleMaker.makeRule(maxVersionsRule), + }, + }, + ], + }); + console.log(`Created column family ${family.name}`); + // [END bigtable_create_family_gc_max_versions] + + console.log(); + console.log('Creating column family cf3 with union GC rule...'); + // [START bigtable_create_family_gc_union] + // Create a column family with GC policy to drop data that matches at least one condition. + + // Define a GC rule to drop cells older than 5 days or not the most recent version + const unionRule = { + ruleType: 'union', + maxVersions: 1, + maxAge: { + seconds: 60 * 60 * 24 * 5, + nanos: 0, + }, + }; + + [family] = await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf3', + create: { + gcRule: GCRuleMaker.makeRule(unionRule), + }, + }, + ], + }); + console.log(`Created column family ${family.name}`); + // [END bigtable_create_family_gc_union] + + console.log(); + console.log('Creating column family cf4 with intersect GC rule...'); + // [START bigtable_create_family_gc_intersection] + // Create a column family with GC policy to drop data that matches all conditions + + // GC rule: Drop cells older than 5 days AND older than the most recent 2 versions + const intersectionRule = { + ruleType: 'intersection', + maxVersions: 2, + maxAge: { + seconds: 60 * 60 * 24 * 5, + nanos: 0, + }, + }; + [family] = await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf4', + create: { + gcRule: GCRuleMaker.makeRule(intersectionRule), + }, + }, + ], + }); + console.log(`Created column family ${family.name}`); + // [END bigtable_create_family_gc_intersection] + + console.log(); + console.log('Creating column family cf5 with a nested GC rule...'); + // [START bigtable_create_family_gc_nested] + // Create a nested GC rule: + // Drop cells that are either older than the 10 recent versions + // OR + // Drop cells that are older than a month AND older than the 2 recent versions + const nestedRule = { + ruleType: 'union', + maxVersions: 10, + rule: { + ruleType: 'intersection', + maxVersions: 2, + maxAge: { + // one month + seconds: 60 * 60 * 24 * 30, + nanos: 0, + }, + }, + }; + + [family] = await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf5', + create: { + gcRule: GCRuleMaker.makeRule(nestedRule), + }, + }, + ], + }); + console.log(`Created column family ${family.name}`); + // [END bigtable_create_family_gc_nested] + + console.log(); + console.log('Printing ID and GC Rule for all column families...'); + // [START bigtable_list_column_families] + // List all families in the table with GC rules + const [families] = await table.getFamilies(); + // Print ID, GC Rule for each column family + families.forEach(family => { + const metadata = JSON.stringify(family.metadata); + console.log(`Column family: ${family.id}, Metadata: ${metadata}`); + /* Sample output: + Column family: projects/{{projectId}}/instances/my-instance/tables/my-table/columnFamilies/cf4, + Metadata: {"gcRule":{"intersection":{"rules":[{"maxAge":{"seconds":"432000","nanos":0},"rule":"maxAge"},{"maxNumVersions":2,"rule":"maxNumVersions"}]},"rule":"intersection"}} + */ + }); + // [END bigtable_list_column_families] + + console.log('\nUpdating column family cf1 GC rule...'); + // [START bigtable_update_gc_rule] + // Update the column family metadata to update the GC rule + + // Create a reference to the column family + family = table.family('cf1'); + + // Update a column family GC rule + const updatedMetadata = { + rule: { + versions: 1, + }, + }; + + const [apiResponse] = await family.setMetadata(updatedMetadata); + console.log(`Updated GC rule: ${JSON.stringify(apiResponse)}`); + // [END bigtable_update_gc_rule] + + console.log('\nPrint updated column family cf1 GC rule...'); + // [START bigtable_family_get_gc_rule] + // Retrieve column family metadata (Id, column family GC rule) + const [metadata] = await family.getMetadata(); + console.log(`Metadata: ${JSON.stringify(metadata)}`); + // [END bigtable_family_get_gc_rule] + + console.log('\nDelete a column family cf2...'); + // [START bigtable_delete_family] + // Delete a column family + await family.delete(); + console.log(`${family.id} deleted successfully\n`); + // [END bigtable_delete_family] + console.log( + 'Run node $0 delete --instance [instanceID] --table [tableID] to delete the table.\n', + ); +} + +async function deleteTable(instanceID, tableID) { + // const instanceID = "my-instance"; + // const tableID = "my-bigtable-ID"; + const bigtableClient = new Bigtable(); + const instance = bigtableClient.instance(instanceID); + const table = instance.table(tableID); + // [START bigtable_delete_table] + // Delete the entire table + console.log('Delete the table.'); + await table.delete(); + console.log(`Table deleted: ${table.id}`); + // [END bigtable_delete_table] +} + +runTableOperations('dan-bigtable-instance', 'Hello-Bigtable23'); \ No newline at end of file From 7adfb6620a4e0d2bd51db785b90e09607dfaea32 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Mon, 25 Aug 2025 14:17:10 -0400 Subject: [PATCH 32/96] Hardcode instance name --- samples/examples/table-admin.js | 31 +-- samples/samples-again/table-admin.js | 288 --------------------------- 2 files changed, 1 insertion(+), 318 deletions(-) delete mode 100644 samples/samples-again/table-admin.js diff --git a/samples/examples/table-admin.js b/samples/examples/table-admin.js index f68bb075c..0ffe4bc49 100644 --- a/samples/examples/table-admin.js +++ b/samples/examples/table-admin.js @@ -285,33 +285,4 @@ async function deleteTable(instanceID, tableID) { // [END bigtable_delete_table] } -require('yargs') - .demand(1) - .command( - 'run', - 'Create a table (if does not exist) and run basic table operations.', - {}, - argv => runTableOperations(argv.instance, argv.table), - ) - .example( - 'node $0 run --instance [instanceID] --table [tableID]', - 'Create a table (if does not exist) and run basic table operations.', - ) - .wrap(120) - .command('delete', 'Delete table.', {}, - argv => deleteTable(argv.instance, argv.table), - ) - .example( - 'node $0 delete --instance [instanceID] --table [tableID]', - 'Delete a table.', - ) - .wrap(120) - .nargs('instance', 1) - .nargs('table', 1) - .describe('instance', 'Cloud Bigtable Instance ID') - .describe('table', 'Cloud Bigtable Table ID') - .demandOption(['instance', 'table']) - .recommendCommands() - .epilogue('For more information, see https://cloud.google.com/bigtable/docs') - .help() - .strict().argv; +runTableOperations('dan-bigtable-instance', 'Hello-Bigtable23'); \ No newline at end of file diff --git a/samples/samples-again/table-admin.js b/samples/samples-again/table-admin.js deleted file mode 100644 index 0ffe4bc49..000000000 --- a/samples/samples-again/table-admin.js +++ /dev/null @@ -1,288 +0,0 @@ -// Copyright 2018 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. - -// Imports the Google Cloud client library -const {Bigtable, GCRuleMaker} = require('@google-cloud/bigtable'); -const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; -const adminClient = new BigtableTableAdminClient(); - -async function runTableOperations(instanceID, tableID) { - const bigtable = new Bigtable(); - const projectId = await adminClient.getProjectId(); - // The request will only work if the projectName doesn't contain the {{projectId}} token. - bigtable.projectName = `projects/${projectId}`; - const instance = bigtable.instance(instanceID); - const table = instance.table(tableID); - - // Check if table exists - console.log(); - console.log('Checking if table exists...'); - const [tableExists] = await table.exists(); - if (!tableExists) { - // Create table if does not exist - console.log(`Table does not exist. Creating table ${tableID}`); - const request = { - parent: adminClient.instancePath(projectId, instanceID), - tableId: tableID, - table: { - columnFamilies: { - follows: {}, - }, - }, - }; - await adminClient.createTable(request); - } else { - console.log('Table exists.'); - } - - console.log(); - console.log('Listing tables in current project...'); - // [START bigtable_list_tables] - // List tables in current project - const [tables] = await instance.getTables(); - tables.forEach(table => { - console.log(table.id); - }); - // [END bigtable_list_tables] - - console.log(); - console.log('Printing table metadata...'); - // [START bigtable_get_table_metadata] - // Get table metadata, and apply a view to the table fields - // Supported views include ID, schema or full - // View defaults to schema if unspecified. - const options = { - view: 'id', - }; - const [tableMetadata] = await table.getMetadata(options); - console.log(`Metadata: ${JSON.stringify(tableMetadata)}`); - // [END bigtable_get_table_metadata] - - console.log(); - console.log('Creating column family cf1 with max age GC rule...'); - // [START bigtable_create_family_gc_max_age] - // Create a column family with GC policy : maximum age - // where age = current time minus cell timestamp - - // Define the GC rule to retain data with max age of 5 days - const maxAgeRule = { - rule: { - maxAge: { - // Value must be atleast 1 millisecond - seconds: 60 * 60 * 24 * 5, - nanos: 0, - }, - }, - }; - let [family] = await adminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: 'cf1', - create: { - gcRule: GCRuleMaker.makeRule(maxAgeRule), - }, - }, - ], - }); - console.log(`Created column family ${family.name}`); - // [END bigtable_create_family_gc_max_age] - - console.log(); - console.log('Creating column family cf2 with max versions GC rule...'); - // [START bigtable_create_family_gc_max_versions] - // Create a column family with GC policy : most recent N versions - // where 1 = most recent version - - // Define the GC policy to retain only the most recent 2 versions - const maxVersionsRule = { - rule: { - maxVersions: 2, - }, - }; - - // Create a column family with given GC rule - [family] = await adminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: 'cf2', - create: { - gcRule: GCRuleMaker.makeRule(maxVersionsRule), - }, - }, - ], - }); - console.log(`Created column family ${family.name}`); - // [END bigtable_create_family_gc_max_versions] - - console.log(); - console.log('Creating column family cf3 with union GC rule...'); - // [START bigtable_create_family_gc_union] - // Create a column family with GC policy to drop data that matches at least one condition. - - // Define a GC rule to drop cells older than 5 days or not the most recent version - const unionRule = { - ruleType: 'union', - maxVersions: 1, - maxAge: { - seconds: 60 * 60 * 24 * 5, - nanos: 0, - }, - }; - - [family] = await adminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: 'cf3', - create: { - gcRule: GCRuleMaker.makeRule(unionRule), - }, - }, - ], - }); - console.log(`Created column family ${family.name}`); - // [END bigtable_create_family_gc_union] - - console.log(); - console.log('Creating column family cf4 with intersect GC rule...'); - // [START bigtable_create_family_gc_intersection] - // Create a column family with GC policy to drop data that matches all conditions - - // GC rule: Drop cells older than 5 days AND older than the most recent 2 versions - const intersectionRule = { - ruleType: 'intersection', - maxVersions: 2, - maxAge: { - seconds: 60 * 60 * 24 * 5, - nanos: 0, - }, - }; - [family] = await adminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: 'cf4', - create: { - gcRule: GCRuleMaker.makeRule(intersectionRule), - }, - }, - ], - }); - console.log(`Created column family ${family.name}`); - // [END bigtable_create_family_gc_intersection] - - console.log(); - console.log('Creating column family cf5 with a nested GC rule...'); - // [START bigtable_create_family_gc_nested] - // Create a nested GC rule: - // Drop cells that are either older than the 10 recent versions - // OR - // Drop cells that are older than a month AND older than the 2 recent versions - const nestedRule = { - ruleType: 'union', - maxVersions: 10, - rule: { - ruleType: 'intersection', - maxVersions: 2, - maxAge: { - // one month - seconds: 60 * 60 * 24 * 30, - nanos: 0, - }, - }, - }; - - [family] = await adminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: 'cf5', - create: { - gcRule: GCRuleMaker.makeRule(nestedRule), - }, - }, - ], - }); - console.log(`Created column family ${family.name}`); - // [END bigtable_create_family_gc_nested] - - console.log(); - console.log('Printing ID and GC Rule for all column families...'); - // [START bigtable_list_column_families] - // List all families in the table with GC rules - const [families] = await table.getFamilies(); - // Print ID, GC Rule for each column family - families.forEach(family => { - const metadata = JSON.stringify(family.metadata); - console.log(`Column family: ${family.id}, Metadata: ${metadata}`); - /* Sample output: - Column family: projects/{{projectId}}/instances/my-instance/tables/my-table/columnFamilies/cf4, - Metadata: {"gcRule":{"intersection":{"rules":[{"maxAge":{"seconds":"432000","nanos":0},"rule":"maxAge"},{"maxNumVersions":2,"rule":"maxNumVersions"}]},"rule":"intersection"}} - */ - }); - // [END bigtable_list_column_families] - - console.log('\nUpdating column family cf1 GC rule...'); - // [START bigtable_update_gc_rule] - // Update the column family metadata to update the GC rule - - // Create a reference to the column family - family = table.family('cf1'); - - // Update a column family GC rule - const updatedMetadata = { - rule: { - versions: 1, - }, - }; - - const [apiResponse] = await family.setMetadata(updatedMetadata); - console.log(`Updated GC rule: ${JSON.stringify(apiResponse)}`); - // [END bigtable_update_gc_rule] - - console.log('\nPrint updated column family cf1 GC rule...'); - // [START bigtable_family_get_gc_rule] - // Retrieve column family metadata (Id, column family GC rule) - const [metadata] = await family.getMetadata(); - console.log(`Metadata: ${JSON.stringify(metadata)}`); - // [END bigtable_family_get_gc_rule] - - console.log('\nDelete a column family cf2...'); - // [START bigtable_delete_family] - // Delete a column family - await family.delete(); - console.log(`${family.id} deleted successfully\n`); - // [END bigtable_delete_family] - console.log( - 'Run node $0 delete --instance [instanceID] --table [tableID] to delete the table.\n', - ); -} - -async function deleteTable(instanceID, tableID) { - // const instanceID = "my-instance"; - // const tableID = "my-bigtable-ID"; - const bigtableClient = new Bigtable(); - const instance = bigtableClient.instance(instanceID); - const table = instance.table(tableID); - // [START bigtable_delete_table] - // Delete the entire table - console.log('Delete the table.'); - await table.delete(); - console.log(`Table deleted: ${table.id}`); - // [END bigtable_delete_table] -} - -runTableOperations('dan-bigtable-instance', 'Hello-Bigtable23'); \ No newline at end of file From c5ed91969496fe84cbf6c07c9d2dd616be9713cf Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Mon, 25 Aug 2025 14:41:54 -0400 Subject: [PATCH 33/96] delete the examples folder --- samples/examples/hello-world.js | 135 ---------- samples/examples/instance-create-table.js | 30 --- samples/examples/table-admin.js | 288 ---------------------- samples/examples/table-create-family.js | 31 --- 4 files changed, 484 deletions(-) delete mode 100644 samples/examples/hello-world.js delete mode 100644 samples/examples/instance-create-table.js delete mode 100644 samples/examples/table-admin.js delete mode 100644 samples/examples/table-create-family.js diff --git a/samples/examples/hello-world.js b/samples/examples/hello-world.js deleted file mode 100644 index cd2f20364..000000000 --- a/samples/examples/hello-world.js +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright 2018 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. - -/** - * A minimal application that demonstrates using the Nodejs Google Cloud API - * to connect to and interact with Cloud Bigtable. See - * https://github.com/googleapis/nodejs-bigtable/blob/master/samples/hello-world/README.md - * for more details - */ - -// This file will only work on node v8.x since it uses async/await. -// A version of this script is available for node v6.x in index.v6.js - -// [START bigtable_hw_imports] -const {Bigtable} = require('@google-cloud/bigtable'); -// [END bigtable_hw_imports] - -const TABLE_ID = 'Hello-Bigtable'; -const COLUMN_FAMILY_ID = 'cf1'; -const COLUMN_QUALIFIER = 'greeting'; -const INSTANCE_ID = process.env.INSTANCE_ID; - -if (!INSTANCE_ID) { - throw new Error('Environment variables for INSTANCE_ID must be set!'); -} - -const getRowGreeting = row => { - return row.data[COLUMN_FAMILY_ID][COLUMN_QUALIFIER][0].value; -}; - -(async () => { - try { - // [START bigtable_hw_connect] - const bigtableClient = new Bigtable(); - const instance = bigtableClient.instance(INSTANCE_ID); - // [END bigtable_hw_connect] - - // [START bigtable_hw_create_table] - const table = instance.table(TABLE_ID); - const [tableExists] = await table.exists(); - if (!tableExists) { - console.log(`Creating table ${TABLE_ID}`); - const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; - const adminClient = new BigtableTableAdminClient(); - const projectId = await adminClient.getProjectId(); - await adminClient.createTable({ - parent: adminClient.instancePath(projectId, INSTANCE_ID), - tableId: TABLE_ID, - table: { - columnFamilies: { - [COLUMN_FAMILY_ID]: { - gcRule: { - maxNumVersions: 1, - }, - }, - }, - }, - }); - } - // [END bigtable_hw_create_table] - - // [START bigtable_hw_write_rows] - console.log('Write some greetings to the table'); - const greetings = ['Hello World!', 'Hello Bigtable!', 'Hello Node!']; - const rowsToInsert = greetings.map((greeting, index) => ({ - // Note: This example uses sequential numeric IDs for simplicity, but this - // pattern can result in poor performance in a production application. - // Rows are stored in sorted order by key, so sequential keys can result - // in poor distribution of operations across nodes. - // - // For more information about how to design an effective schema for Cloud - // Bigtable, see the documentation: - // https://cloud.google.com/bigtable/docs/schema-design - key: `greeting${index}`, - data: { - [COLUMN_FAMILY_ID]: { - [COLUMN_QUALIFIER]: { - // Setting the timestamp allows the client to perform retries. If - // server-side time is used, retries may cause multiple cells to - // be generated. - timestamp: new Date(), - value: greeting, - }, - }, - }, - })); - await table.insert(rowsToInsert); - // [END bigtable_hw_write_rows] - - // [START bigtable_hw_create_filter] - const filter = [ - { - column: { - cellLimit: 1, // Only retrieve the most recent version of the cell. - }, - }, - ]; - // [END bigtable_hw_create_filter] - - // [START bigtable_hw_get_with_filter] - console.log('Reading a single row by row key'); - const [singleRow] = await table.row('greeting0').get({filter}); - console.log(` Read: ${getRowGreeting(singleRow)}`); - // [END bigtable_hw_get_with_filter] - - // [START bigtable_hw_scan_with_filter] - console.log('Reading the entire table'); - // Note: For improved performance in production applications, call - // `Table#readStream` to get a stream of rows. See the API documentation: - // https://cloud.google.com/nodejs/docs/reference/bigtable/latest/Table#createReadStream - const [allRows] = await table.getRows({filter}); - for (const row of allRows) { - console.log(` Read: ${getRowGreeting(row)}`); - } - // [END bigtable_hw_scan_with_filter] - - // [START bigtable_hw_delete_table] - console.log('Delete the table'); - await table.delete(); - // [END bigtable_hw_delete_table] - } catch (error) { - console.error('Something went wrong:', error); - } -})(); diff --git a/samples/examples/instance-create-table.js b/samples/examples/instance-create-table.js deleted file mode 100644 index e50db0447..000000000 --- a/samples/examples/instance-create-table.js +++ /dev/null @@ -1,30 +0,0 @@ -async function main(instanceId = 'YOUR_INSTANCE_ID', tableId = 'YOUR_TABLE_ID') { - // [START bigtable_api_create_table] - const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; - const adminClient = new BigtableTableAdminClient(); - const projectId = await adminClient.getProjectId(); - - const request = { - parent: adminClient.instancePath(projectId, instanceId), - tableId: tableId, - table: { - columnFamilies: { - follows: {}, - }, - }, - }; - - adminClient - .createTable(request) - .then(result => { - const newTable = result[0]; - console.log(`Table ${newTable.name} created successfully.`); - }) - .catch(err => { - console.error(err); - }); - // [END bigtable_api_create_table] -} - -const args = process.argv.slice(2); -main(...args).catch(console.error); diff --git a/samples/examples/table-admin.js b/samples/examples/table-admin.js deleted file mode 100644 index 0ffe4bc49..000000000 --- a/samples/examples/table-admin.js +++ /dev/null @@ -1,288 +0,0 @@ -// Copyright 2018 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. - -// Imports the Google Cloud client library -const {Bigtable, GCRuleMaker} = require('@google-cloud/bigtable'); -const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; -const adminClient = new BigtableTableAdminClient(); - -async function runTableOperations(instanceID, tableID) { - const bigtable = new Bigtable(); - const projectId = await adminClient.getProjectId(); - // The request will only work if the projectName doesn't contain the {{projectId}} token. - bigtable.projectName = `projects/${projectId}`; - const instance = bigtable.instance(instanceID); - const table = instance.table(tableID); - - // Check if table exists - console.log(); - console.log('Checking if table exists...'); - const [tableExists] = await table.exists(); - if (!tableExists) { - // Create table if does not exist - console.log(`Table does not exist. Creating table ${tableID}`); - const request = { - parent: adminClient.instancePath(projectId, instanceID), - tableId: tableID, - table: { - columnFamilies: { - follows: {}, - }, - }, - }; - await adminClient.createTable(request); - } else { - console.log('Table exists.'); - } - - console.log(); - console.log('Listing tables in current project...'); - // [START bigtable_list_tables] - // List tables in current project - const [tables] = await instance.getTables(); - tables.forEach(table => { - console.log(table.id); - }); - // [END bigtable_list_tables] - - console.log(); - console.log('Printing table metadata...'); - // [START bigtable_get_table_metadata] - // Get table metadata, and apply a view to the table fields - // Supported views include ID, schema or full - // View defaults to schema if unspecified. - const options = { - view: 'id', - }; - const [tableMetadata] = await table.getMetadata(options); - console.log(`Metadata: ${JSON.stringify(tableMetadata)}`); - // [END bigtable_get_table_metadata] - - console.log(); - console.log('Creating column family cf1 with max age GC rule...'); - // [START bigtable_create_family_gc_max_age] - // Create a column family with GC policy : maximum age - // where age = current time minus cell timestamp - - // Define the GC rule to retain data with max age of 5 days - const maxAgeRule = { - rule: { - maxAge: { - // Value must be atleast 1 millisecond - seconds: 60 * 60 * 24 * 5, - nanos: 0, - }, - }, - }; - let [family] = await adminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: 'cf1', - create: { - gcRule: GCRuleMaker.makeRule(maxAgeRule), - }, - }, - ], - }); - console.log(`Created column family ${family.name}`); - // [END bigtable_create_family_gc_max_age] - - console.log(); - console.log('Creating column family cf2 with max versions GC rule...'); - // [START bigtable_create_family_gc_max_versions] - // Create a column family with GC policy : most recent N versions - // where 1 = most recent version - - // Define the GC policy to retain only the most recent 2 versions - const maxVersionsRule = { - rule: { - maxVersions: 2, - }, - }; - - // Create a column family with given GC rule - [family] = await adminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: 'cf2', - create: { - gcRule: GCRuleMaker.makeRule(maxVersionsRule), - }, - }, - ], - }); - console.log(`Created column family ${family.name}`); - // [END bigtable_create_family_gc_max_versions] - - console.log(); - console.log('Creating column family cf3 with union GC rule...'); - // [START bigtable_create_family_gc_union] - // Create a column family with GC policy to drop data that matches at least one condition. - - // Define a GC rule to drop cells older than 5 days or not the most recent version - const unionRule = { - ruleType: 'union', - maxVersions: 1, - maxAge: { - seconds: 60 * 60 * 24 * 5, - nanos: 0, - }, - }; - - [family] = await adminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: 'cf3', - create: { - gcRule: GCRuleMaker.makeRule(unionRule), - }, - }, - ], - }); - console.log(`Created column family ${family.name}`); - // [END bigtable_create_family_gc_union] - - console.log(); - console.log('Creating column family cf4 with intersect GC rule...'); - // [START bigtable_create_family_gc_intersection] - // Create a column family with GC policy to drop data that matches all conditions - - // GC rule: Drop cells older than 5 days AND older than the most recent 2 versions - const intersectionRule = { - ruleType: 'intersection', - maxVersions: 2, - maxAge: { - seconds: 60 * 60 * 24 * 5, - nanos: 0, - }, - }; - [family] = await adminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: 'cf4', - create: { - gcRule: GCRuleMaker.makeRule(intersectionRule), - }, - }, - ], - }); - console.log(`Created column family ${family.name}`); - // [END bigtable_create_family_gc_intersection] - - console.log(); - console.log('Creating column family cf5 with a nested GC rule...'); - // [START bigtable_create_family_gc_nested] - // Create a nested GC rule: - // Drop cells that are either older than the 10 recent versions - // OR - // Drop cells that are older than a month AND older than the 2 recent versions - const nestedRule = { - ruleType: 'union', - maxVersions: 10, - rule: { - ruleType: 'intersection', - maxVersions: 2, - maxAge: { - // one month - seconds: 60 * 60 * 24 * 30, - nanos: 0, - }, - }, - }; - - [family] = await adminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: 'cf5', - create: { - gcRule: GCRuleMaker.makeRule(nestedRule), - }, - }, - ], - }); - console.log(`Created column family ${family.name}`); - // [END bigtable_create_family_gc_nested] - - console.log(); - console.log('Printing ID and GC Rule for all column families...'); - // [START bigtable_list_column_families] - // List all families in the table with GC rules - const [families] = await table.getFamilies(); - // Print ID, GC Rule for each column family - families.forEach(family => { - const metadata = JSON.stringify(family.metadata); - console.log(`Column family: ${family.id}, Metadata: ${metadata}`); - /* Sample output: - Column family: projects/{{projectId}}/instances/my-instance/tables/my-table/columnFamilies/cf4, - Metadata: {"gcRule":{"intersection":{"rules":[{"maxAge":{"seconds":"432000","nanos":0},"rule":"maxAge"},{"maxNumVersions":2,"rule":"maxNumVersions"}]},"rule":"intersection"}} - */ - }); - // [END bigtable_list_column_families] - - console.log('\nUpdating column family cf1 GC rule...'); - // [START bigtable_update_gc_rule] - // Update the column family metadata to update the GC rule - - // Create a reference to the column family - family = table.family('cf1'); - - // Update a column family GC rule - const updatedMetadata = { - rule: { - versions: 1, - }, - }; - - const [apiResponse] = await family.setMetadata(updatedMetadata); - console.log(`Updated GC rule: ${JSON.stringify(apiResponse)}`); - // [END bigtable_update_gc_rule] - - console.log('\nPrint updated column family cf1 GC rule...'); - // [START bigtable_family_get_gc_rule] - // Retrieve column family metadata (Id, column family GC rule) - const [metadata] = await family.getMetadata(); - console.log(`Metadata: ${JSON.stringify(metadata)}`); - // [END bigtable_family_get_gc_rule] - - console.log('\nDelete a column family cf2...'); - // [START bigtable_delete_family] - // Delete a column family - await family.delete(); - console.log(`${family.id} deleted successfully\n`); - // [END bigtable_delete_family] - console.log( - 'Run node $0 delete --instance [instanceID] --table [tableID] to delete the table.\n', - ); -} - -async function deleteTable(instanceID, tableID) { - // const instanceID = "my-instance"; - // const tableID = "my-bigtable-ID"; - const bigtableClient = new Bigtable(); - const instance = bigtableClient.instance(instanceID); - const table = instance.table(tableID); - // [START bigtable_delete_table] - // Delete the entire table - console.log('Delete the table.'); - await table.delete(); - console.log(`Table deleted: ${table.id}`); - // [END bigtable_delete_table] -} - -runTableOperations('dan-bigtable-instance', 'Hello-Bigtable23'); \ No newline at end of file diff --git a/samples/examples/table-create-family.js b/samples/examples/table-create-family.js deleted file mode 100644 index a6ead80cd..000000000 --- a/samples/examples/table-create-family.js +++ /dev/null @@ -1,31 +0,0 @@ -async function main(instanceId = 'YOUR_INSTANCE_ID', tableId = 'YOUR_TABLE_ID', familyId = 'YOUR_FAMILY_ID') { - // [START bigtable_api_create_family] - const {BigtableTableAdminClient, GCRuleMaker} = require('@google-cloud/bigtable').v2; - const adminClient = new BigtableTableAdminClient(); - const projectId = await adminClient.getProjectId(); - const options = {}; - - adminClient - .modifyColumnFamilies({ - name: adminClient.tablePath(projectId, instanceId, tableId), - modifications: [ - { - id: familyId, - create: { - gcRule: GCRuleMaker.makeRule(options), - }, - }, - ], - }) - .then(result => { - const family = result[0]; - console.log(`Family ${family.name} created successfully.`); - }) - .catch(err => { - console.error(err); - }); - // [END bigtable_api_create_family] -} - -const args = process.argv.slice(2); -main(...args).catch(console.error); From 29dc22231af3802c4a42e050dbed59f76452ad16 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Mon, 25 Aug 2025 14:48:36 -0400 Subject: [PATCH 34/96] remove options --- samples/hello-world/index.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/samples/hello-world/index.js b/samples/hello-world/index.js index 37c78178f..28b5c4630 100644 --- a/samples/hello-world/index.js +++ b/samples/hello-world/index.js @@ -53,16 +53,6 @@ const getRowGreeting = row => { console.log(`Creating table ${TABLE_ID}`); const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); - const options = { - families: [ - { - name: COLUMN_FAMILY_ID, - rule: { - versions: 1, - }, - }, - ], - }; const projectId = await adminClient.getProjectId(); await adminClient.createTable({ parent: adminClient.instancePath(projectId, INSTANCE_ID), From fa41c121031872934b9c11353380afa736ad115e Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Mon, 25 Aug 2025 15:01:52 -0400 Subject: [PATCH 35/96] add header --- samples/api-reference-doc-snippets/table.js | 2 +- src/gc-rule-maker.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/samples/api-reference-doc-snippets/table.js b/samples/api-reference-doc-snippets/table.js index 75b66dba8..744227242 100644 --- a/samples/api-reference-doc-snippets/table.js +++ b/samples/api-reference-doc-snippets/table.js @@ -412,4 +412,4 @@ const snippets = { }, }; -module.exports = snippets; \ No newline at end of file +module.exports = snippets; diff --git a/src/gc-rule-maker.ts b/src/gc-rule-maker.ts index 4c4c3f146..7c2d1a8ec 100644 --- a/src/gc-rule-maker.ts +++ b/src/gc-rule-maker.ts @@ -1,3 +1,17 @@ +// Copyright 2025 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. + import {IGcRule} from './family'; import * as protos from '../protos/protos'; From 76146b92141182440ae8d8cb338aca6037598cdf Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 28 Aug 2025 14:29:51 -0400 Subject: [PATCH 36/96] The rest of the samples should use BigtableTableAdminClient instread --- .../backups.delete.js | 17 +- samples/api-reference-doc-snippets/family.js | 157 +++++++++++------- samples/api-reference-doc-snippets/table.js | 102 ++++++++---- samples/hello-world/index.js | 8 +- 4 files changed, 176 insertions(+), 108 deletions(-) diff --git a/samples/api-reference-doc-snippets/backups.delete.js b/samples/api-reference-doc-snippets/backups.delete.js index 0b5011867..d7d3ea3c2 100644 --- a/samples/api-reference-doc-snippets/backups.delete.js +++ b/samples/api-reference-doc-snippets/backups.delete.js @@ -14,28 +14,25 @@ async function main( instanceId = 'YOUR_INSTANCE_ID', - tableId = 'YOUR_TABLE_ID', clusterId = 'YOUR_CLUSTER_ID', backupId = 'YOUR_BACKUP_ID', ) { // [START bigtable_api_delete_backup] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const tableAdminClient = new BigtableTableAdminClient(); async function deleteBackup() { /** * TODO(developer): Uncomment these variables before running the sample. */ // const instanceId = 'YOUR_INSTANCE_ID'; - // const tableId = 'YOUR_TABLE_ID'; // const clusterId = 'YOUR_CLUSTER_ID'; // const backupId = 'YOUR_BACKUP_ID'; - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); - const cluster = table.cluster(clusterId); - const backup = cluster.backup(backupId); - - await backup.delete(); + const projectId = await tableAdminClient.getProjectId(); + const request = { + name: tableAdminClient.backupPath(projectId, instanceId, clusterId, backupId), + }; + await tableAdminClient.deleteBackup(request); console.log(`Backup ${backupId} was deleted successfully.`); } diff --git a/samples/api-reference-doc-snippets/family.js b/samples/api-reference-doc-snippets/family.js index b5224fc21..474d39fe1 100644 --- a/samples/api-reference-doc-snippets/family.js +++ b/samples/api-reference-doc-snippets/family.js @@ -13,16 +13,24 @@ // limitations under the License. const snippets = { - createColmFamily: (instanceId, tableId, familyId) => { + createColmFamily: async (instanceId, tableId, familyId) => { // [START bigtable_api_create_family] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); - const family = table.family(familyId); + const {BigtableTableAdminClient, GCRuleMaker} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); - family - .create() + const request = { + name: adminClient.tablePath(projectId, instanceId, tableId), + modifications: [ + { + id: familyId, + create: {}, + }, + ], + }; + + adminClient + .modifyColumnFamilies(request) .then(result => { const family = result[0]; // let apiResponse = result[1]; @@ -32,36 +40,43 @@ const snippets = { }); // [END bigtable_api_create_family] }, - existsFamily: (instanceId, tableId, familyId) => { + existsFamily: async (instanceId, tableId, familyId) => { // [START bigtable_api_exists_family] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); - const family = table.family(familyId); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); - family - .exists() - .then(result => { - const exists = result[0]; - }) - .catch(err => { - // Handle the error. - }); + const request = { + name: adminClient.tablePath(projectId, instanceId, tableId), + view: 'FAMILY_VIEW_BASIC', + }; + + try { + const [table] = await adminClient.getTable(request); + const exists = table.columnFamilies.hasOwnProperty(familyId); + console.log(`Family ${familyId} exists: ${exists}`); + } catch (err) { + // Handle the error. + console.error(err); + } // [END bigtable_api_exists_family] }, - getFamily: (instanceId, tableId, familyId) => { + getFamily: async (instanceId, tableId, familyId) => { // [START bigtable_api_get_family] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); - const family = table.family(familyId); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); - family - .get() + const request = { + name: adminClient.tablePath(projectId, instanceId, tableId), + view: 'FULL', + }; + + adminClient + .getTable(request) .then(result => { - const family = result[0]; + const table = result[0]; + const family = table.columnFamilies[familyId]; // const apiResponse = result[1]; }) .catch(err => { @@ -69,18 +84,22 @@ const snippets = { }); // [END bigtable_api_get_family] }, - getMetadata: (instanceId, tableId, familyId) => { + getMetadata: async (instanceId, tableId, familyId) => { // [START bigtable_api_get_family_meta] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); - const family = table.family(familyId); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + + const request = { + name: adminClient.tablePath(projectId, instanceId, tableId), + view: 'FULL', + }; - family - .getMetadata() + adminClient + .getTable(request) .then(result => { - const metaData = result[0]; + const table = result[0]; + const metaData = table.columnFamilies[familyId]; // const apiResponse = result[1]; }) .catch(err => { @@ -88,23 +107,31 @@ const snippets = { }); // [END bigtable_api_get_family_meta] }, - setMetadata: (instanceId, tableId, familyId) => { + setMetadata: async (instanceId, tableId, familyId) => { // [START bigtable_api_set_family_meta] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); - const family = table.family(familyId); + const {BigtableTableAdminClient, GCRuleMaker} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); - const metadata = { - rule: { - versions: 2, - union: true, - }, + const rule = { + versions: 2, + union: true, }; - family - .setMetadata(metadata) + const request = { + name: adminClient.tablePath(projectId, instanceId, tableId), + modifications: [ + { + id: familyId, + update: { + gcRule: GCRuleMaker.makeRule(rule), + }, + }, + ], + }; + + adminClient + .modifyColumnFamilies(request) .then(result => { const apiResponse = result[0]; }) @@ -113,16 +140,24 @@ const snippets = { }); // [END bigtable_api_set_family_meta] }, - delFamily: (instanceId, tableId, familyId) => { + delFamily: async (instanceId, tableId, familyId) => { // [START bigtable_api_del_family] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); - const family = table.family(familyId); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + + const request = { + name: adminClient.tablePath(projectId, instanceId, tableId), + modifications: [ + { + id: familyId, + drop: true, + }, + ], + }; - family - .delete() + adminClient + .modifyColumnFamilies(request) .then(result => { const apiResponse = result[0]; }) diff --git a/samples/api-reference-doc-snippets/table.js b/samples/api-reference-doc-snippets/table.js index 744227242..6ba023378 100644 --- a/samples/api-reference-doc-snippets/table.js +++ b/samples/api-reference-doc-snippets/table.js @@ -42,29 +42,42 @@ const snippets = { // [END bigtable_api_create_table] }, - existsTable: (instanceId, tableId) => { - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); - + existsTable: async (instanceId, tableId) => { // [START bigtable_api_exists_table] - table - .exists() - .then(result => { - const exists = result[0]; - }) - .catch(err => { + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + + const request = { + name: adminClient.tablePath(projectId, instanceId, tableId), + }; + + try { + await adminClient.getTable(request); + console.log(`Table ${tableId} exists.`); + } catch (err) { + if (err.code === 5) { + console.log(`Table ${tableId} does not exist.`); + } else { // Handle the error. - }); + console.error(err); + } + } // [END bigtable_api_exists_table] }, - getTable: (instanceId, tableId) => { - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); - + getTable: async (instanceId, tableId) => { // [START bigtable_api_get_table] - table - .get() + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + + const request = { + name: adminClient.tablePath(projectId, instanceId, tableId), + }; + + adminClient + .getTable(request) .then(result => { const table = result[0]; // const apiResponse = result[1]; @@ -75,13 +88,19 @@ const snippets = { // [END bigtable_api_get_table] }, - getMetadata: (instanceId, tableId) => { - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); - + getMetadata: async (instanceId, tableId) => { // [START bigtable_api_get_table_meta] - table - .getMetadata() + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + + const request = { + name: adminClient.tablePath(projectId, instanceId, tableId), + view: 'FULL', + }; + + adminClient + .getTable(request) .then(result => { const metaData = result[0]; // const apiResponse = result[1]; @@ -130,15 +149,21 @@ const snippets = { // [END bigtable_api_create_family] }, - getFamilies: (instanceId, tableId) => { - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); - + getFamilies: async (instanceId, tableId) => { // [START bigtable_api_get_families] - table - .getFamilies() + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + + const request = { + name: adminClient.tablePath(projectId, instanceId, tableId), + view: 'FULL', + }; + + adminClient + .getTable(request) .then(result => { - const families = result[0]; + const families = result[0].columnFamilies; }) .catch(err => { // Handle the error. @@ -395,13 +420,18 @@ const snippets = { // [END bigtable_api_del_rows] }, - delTable: (instanceId, tableId) => { - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); - + delTable: async (instanceId, tableId) => { // [START bigtable_api_del_table] - table - .delete() + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + + const request = { + name: adminClient.tablePath(projectId, instanceId, tableId), + }; + + adminClient + .deleteTable(request) .then(result => { const apiResponse = result[0]; }) diff --git a/samples/hello-world/index.js b/samples/hello-world/index.js index 28b5c4630..1d57dc2e2 100644 --- a/samples/hello-world/index.js +++ b/samples/hello-world/index.js @@ -127,7 +127,13 @@ const getRowGreeting = row => { // [START bigtable_hw_delete_table] console.log('Delete the table'); - await table.delete(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const request = { + name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + }; + await adminClient.deleteTable(request); // [END bigtable_hw_delete_table] } catch (error) { console.error('Something went wrong:', error); From 3cf912afc2478512360ca9dc33931257564dffb5 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 28 Aug 2025 14:54:00 -0400 Subject: [PATCH 37/96] Update more tables code --- samples/hello-world/index.js | 14 ++++++-- samples/tableadmin.js | 67 +++++++++++++++++++++++++----------- 2 files changed, 58 insertions(+), 23 deletions(-) diff --git a/samples/hello-world/index.js b/samples/hello-world/index.js index 1d57dc2e2..41e2b6657 100644 --- a/samples/hello-world/index.js +++ b/samples/hello-world/index.js @@ -47,8 +47,18 @@ const getRowGreeting = row => { // [END bigtable_hw_connect] // [START bigtable_hw_create_table] - const table = instance.table(TABLE_ID); - const [tableExists] = await table.exists(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + + let tableExists = true; + try { + await adminClient.getTable({name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID)}); + } catch (e) { + if (e.code === 5) { + tableExists = false; + } + } if (!tableExists) { console.log(`Creating table ${TABLE_ID}`); const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; diff --git a/samples/tableadmin.js b/samples/tableadmin.js index df29d1353..0b7f159de 100644 --- a/samples/tableadmin.js +++ b/samples/tableadmin.js @@ -28,7 +28,14 @@ async function runTableOperations(instanceID, tableID) { // Check if table exists console.log(); console.log('Checking if table exists...'); - const [tableExists] = await table.exists(); + let tableExists = true; + try { + await adminClient.getTable({name: table.name}); + } catch (e) { + if (e.code === 5) { + tableExists = false; + } + } if (!tableExists) { // Create table if does not exist console.log(`Table does not exist. Creating table ${tableID}`); @@ -50,9 +57,9 @@ async function runTableOperations(instanceID, tableID) { console.log('Listing tables in current project...'); // [START bigtable_list_tables] // List tables in current project - const [tables] = await instance.getTables(); + const [tables] = await adminClient.listTables({parent: instance.name}); tables.forEach(table => { - console.log(table.id); + console.log(table.name); }); // [END bigtable_list_tables] @@ -65,7 +72,7 @@ async function runTableOperations(instanceID, tableID) { const options = { view: 'id', }; - const [tableMetadata] = await table.getMetadata(options); + const [tableMetadata] = await adminClient.getTable({name: table.name, view: options.view}); console.log(`Metadata: ${JSON.stringify(tableMetadata)}`); // [END bigtable_get_table_metadata] @@ -223,25 +230,24 @@ async function runTableOperations(instanceID, tableID) { console.log('Printing ID and GC Rule for all column families...'); // [START bigtable_list_column_families] // List all families in the table with GC rules - const [families] = await table.getFamilies(); + const [tableData] = await adminClient.getTable({name: table.name, view: 'FULL'}); + const families = tableData.columnFamilies; // Print ID, GC Rule for each column family - families.forEach(family => { - const metadata = JSON.stringify(family.metadata); - console.log(`Column family: ${family.id}, Metadata: ${metadata}`); + for (const familyId in families) { + const family = families[familyId]; + const metadata = JSON.stringify(family.gcRule); + console.log(`Column family: ${familyId}, Metadata: ${metadata}`); /* Sample output: Column family: projects/{{projectId}}/instances/my-instance/tables/my-table/columnFamilies/cf4, Metadata: {"gcRule":{"intersection":{"rules":[{"maxAge":{"seconds":"432000","nanos":0},"rule":"maxAge"},{"maxNumVersions":2,"rule":"maxNumVersions"}]},"rule":"intersection"}} */ - }); + } // [END bigtable_list_column_families] console.log('\nUpdating column family cf1 GC rule...'); // [START bigtable_update_gc_rule] // Update the column family metadata to update the GC rule - // Create a reference to the column family - family = table.family('cf1'); - // Update a column family GC rule const updatedMetadata = { rule: { @@ -249,22 +255,41 @@ async function runTableOperations(instanceID, tableID) { }, }; - const [apiResponse] = await family.setMetadata(updatedMetadata); + const [apiResponse] = await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf1', + update: { + gcRule: GCRuleMaker.makeRule(updatedMetadata.rule), + }, + }, + ], + }); console.log(`Updated GC rule: ${JSON.stringify(apiResponse)}`); // [END bigtable_update_gc_rule] console.log('\nPrint updated column family cf1 GC rule...'); // [START bigtable_family_get_gc_rule] // Retrieve column family metadata (Id, column family GC rule) - const [metadata] = await family.getMetadata(); + const [tableData] = await adminClient.getTable({name: table.name, view: 'FULL'}); + const metadata = tableData.columnFamilies['cf1'].gcRule; console.log(`Metadata: ${JSON.stringify(metadata)}`); // [END bigtable_family_get_gc_rule] console.log('\nDelete a column family cf2...'); // [START bigtable_delete_family] // Delete a column family - await family.delete(); - console.log(`${family.id} deleted successfully\n`); + await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf2', + drop: true, + }, + ], + }); + console.log('cf2 deleted successfully\n'); // [END bigtable_delete_family] console.log( 'Run node $0 delete --instance [instanceID] --table [tableID] to delete the table.\n', @@ -274,14 +299,14 @@ async function runTableOperations(instanceID, tableID) { async function deleteTable(instanceID, tableID) { // const instanceID = "my-instance"; // const tableID = "my-bigtable-ID"; - const bigtableClient = new Bigtable(); - const instance = bigtableClient.instance(instanceID); - const table = instance.table(tableID); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); // [START bigtable_delete_table] // Delete the entire table console.log('Delete the table.'); - await table.delete(); - console.log(`Table deleted: ${table.id}`); + await adminClient.deleteTable({name: adminClient.tablePath(projectId, instanceID, tableID)}); + console.log(`Table deleted: ${tableID}`); // [END bigtable_delete_table] } From e9dd0be2c1203854f84e1efc60cce4561d1eefed Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Tue, 2 Sep 2025 17:00:29 -0400 Subject: [PATCH 38/96] commit the api-reference-doc-snippets --- .../backups.create.js | 24 +++++---- .../backups.delete.js | 7 ++- .../api-reference-doc-snippets/backups.get.js | 28 +++++----- .../backups.list.js | 19 +++---- .../backups.update.js | 35 +++++++----- samples/api-reference-doc-snippets/family.js | 6 ++- samples/api-reference-doc-snippets/table.js | 54 +++++++++++-------- 7 files changed, 100 insertions(+), 73 deletions(-) diff --git a/samples/api-reference-doc-snippets/backups.create.js b/samples/api-reference-doc-snippets/backups.create.js index 7ba86596a..85173125a 100644 --- a/samples/api-reference-doc-snippets/backups.create.js +++ b/samples/api-reference-doc-snippets/backups.create.js @@ -19,8 +19,8 @@ async function main( backupId = 'YOUR_BACKUP_ID', ) { // [START bigtable_api_create_backup] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const tableAdminClient = new BigtableTableAdminClient(); async function createBackup() { /** @@ -30,19 +30,23 @@ async function main( // const tableId = 'YOUR_TABLE_ID'; // const clusterId = 'YOUR_CLUSTER_ID'; // const backupId = 'YOUR_BACKUP_ID'; + const projectId = await tableAdminClient.getProjectId(); - const instance = bigtable.instance(instanceId); - const cluster = instance.cluster(clusterId); + const request = { + parent: tableAdminClient.clusterPath(projectId, instanceId, clusterId), + backupId: backupId, + backup: { + sourceTable: tableAdminClient.tablePath(projectId, instanceId, tableId), + expireTime: new Date(Date.now() + 7 * 60 * 60 * 1000), // 7 hours from now + }, + }; - const [backup, operation] = await cluster.createBackup(backupId, { - table: tableId, - expireTime: new Date(Date.now() + 7 * 60 * 60 * 1000), // 7 hours from now - }); + const [operation] = await tableAdminClient.createBackup(request); console.log('Started a table backup operation.'); - await operation.promise(); + const [backup] = await operation.promise(); - console.log(`Backup "${backup.id}" is now ready for use.`); + console.log(`Backup "${backup.name}" is now ready for use.`); } await createBackup(); diff --git a/samples/api-reference-doc-snippets/backups.delete.js b/samples/api-reference-doc-snippets/backups.delete.js index d7d3ea3c2..d8962d941 100644 --- a/samples/api-reference-doc-snippets/backups.delete.js +++ b/samples/api-reference-doc-snippets/backups.delete.js @@ -30,7 +30,12 @@ async function main( // const backupId = 'YOUR_BACKUP_ID'; const projectId = await tableAdminClient.getProjectId(); const request = { - name: tableAdminClient.backupPath(projectId, instanceId, clusterId, backupId), + name: tableAdminClient.backupPath( + projectId, + instanceId, + clusterId, + backupId, + ), }; await tableAdminClient.deleteBackup(request); console.log(`Backup ${backupId} was deleted successfully.`); diff --git a/samples/api-reference-doc-snippets/backups.get.js b/samples/api-reference-doc-snippets/backups.get.js index 013ab6f87..b349af245 100644 --- a/samples/api-reference-doc-snippets/backups.get.js +++ b/samples/api-reference-doc-snippets/backups.get.js @@ -14,40 +14,40 @@ async function main( instanceId = 'YOUR_INSTANCE_ID', - tableId = 'YOUR_TABLE_ID', clusterId = 'YOUR_CLUSTER_ID', backupId = 'YOUR_BACKUP_ID', ) { // [START bigtable_api_get_backup] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const tableAdminClient = new BigtableTableAdminClient(); async function getBackup() { /** * TODO(developer): Uncomment these variables before running the sample. */ // const instanceId = 'YOUR_INSTANCE_ID'; - // const tableId = 'YOUR_TABLE_ID'; // const clusterId = 'YOUR_CLUSTER_ID'; // const backupId = 'YOUR_BACKUP_ID'; - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); - const cluster = table.cluster(clusterId); + const projectId = await tableAdminClient.getProjectId(); - // Create a reference to the backup before performing operations on it. - const backup = cluster.backup(backupId); + const request = { + name: tableAdminClient.backupPath( + projectId, + instanceId, + clusterId, + backupId, + ), + }; - // Get the backup's metadata, with information such as when it will expire - // and how big it is. - const [metadata] = await backup.getMetadata(); + const [metadata] = await tableAdminClient.getBackup(request); console.log(`The backup is ${metadata.sizeBytes} bytes.`); // Time properties have Date helpers to convert to a `PreciseDate`. console.log( - `The backup will auto-delete at ${metadata.expireDate.toISOString()}`, + `The backup will auto-delete at ${new Date(metadata.expireTime.seconds * 1000).toISOString()}`, ); console.log( - `The backup finished being created at ${metadata.endTime.toISOString()}`, + `The backup finished being created at ${new Date(metadata.endTime.seconds * 1000).toISOString()}`, ); } diff --git a/samples/api-reference-doc-snippets/backups.list.js b/samples/api-reference-doc-snippets/backups.list.js index de91e9219..919b78215 100644 --- a/samples/api-reference-doc-snippets/backups.list.js +++ b/samples/api-reference-doc-snippets/backups.list.js @@ -14,30 +14,25 @@ async function main( instanceId = 'YOUR_INSTANCE_ID', - tableId = 'YOUR_TABLE_ID', clusterId = 'YOUR_CLUSTER_ID', ) { // [START bigtable_api_list_backups] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const tableAdminClient = new BigtableTableAdminClient(); async function listBackups() { /** * TODO(developer): Uncomment these variables before running the sample. */ // const instanceId = 'YOUR_INSTANCE_ID'; - // const tableId = 'YOUR_TABLE_ID'; // const clusterId = 'YOUR_CLUSTER_ID'; - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); - const cluster = table.cluster(clusterId); + const projectId = await tableAdminClient.getProjectId(); - const [backupsFromInstance] = await instance.listBackups(); - console.log( - `${backupsFromInstance.length} backups returned from the instance.`, - ); + const request = { + parent: tableAdminClient.clusterPath(projectId, instanceId, clusterId), + }; - const [backupsFromCluster] = await cluster.listBackups(); + const [backupsFromCluster] = await tableAdminClient.listBackups(request); console.log( `${backupsFromCluster.length} backups returned from the cluster.`, ); diff --git a/samples/api-reference-doc-snippets/backups.update.js b/samples/api-reference-doc-snippets/backups.update.js index 04c6e31e0..42430d5aa 100644 --- a/samples/api-reference-doc-snippets/backups.update.js +++ b/samples/api-reference-doc-snippets/backups.update.js @@ -14,32 +14,41 @@ async function main( instanceId = 'YOUR_INSTANCE_ID', - tableId = 'YOUR_TABLE_ID', clusterId = 'YOUR_CLUSTER_ID', backupId = 'YOUR_BACKUP_ID', ) { // [START bigtable_api_update_backup] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const tableAdminClient = new BigtableTableAdminClient(); async function updateBackup() { /** * TODO(developer): Uncomment these variables before running the sample. */ // const instanceId = 'YOUR_INSTANCE_ID'; - // const tableId = 'YOUR_TABLE_ID'; // const clusterId = 'YOUR_CLUSTER_ID'; // const backupId = 'YOUR_BACKUP_ID'; - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); - const cluster = table.cluster(clusterId); - const backup = cluster.backup(backupId); + const projectId = await tableAdminClient.getProjectId(); - // Extend a backup's life by updating its expiry date. - const [metadata] = await backup.setMetadata({ - expireTime: new Date(Date.now() + 24 * 60 * 60 * 1000), // 24 hours - }); - console.log(`The backup will now auto-delete at ${metadata.expireDate}.`); + const request = { + backup: { + name: tableAdminClient.backupPath( + projectId, + instanceId, + clusterId, + backupId, + ), + expireTime: new Date(Date.now() + 24 * 60 * 60 * 1000), // 24 hours + }, + updateMask: { + paths: ['expire_time'], + }, + }; + + const [metadata] = await tableAdminClient.updateBackup(request); + console.log( + `The backup will now auto-delete at ${new Date(metadata.expireTime.seconds * 1000)}.`, + ); } await updateBackup(); diff --git a/samples/api-reference-doc-snippets/family.js b/samples/api-reference-doc-snippets/family.js index 474d39fe1..aad38aa92 100644 --- a/samples/api-reference-doc-snippets/family.js +++ b/samples/api-reference-doc-snippets/family.js @@ -15,7 +15,8 @@ const snippets = { createColmFamily: async (instanceId, tableId, familyId) => { // [START bigtable_api_create_family] - const {BigtableTableAdminClient, GCRuleMaker} = require('@google-cloud/bigtable').v2; + const {BigtableTableAdminClient, GCRuleMaker} = + require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); @@ -109,7 +110,8 @@ const snippets = { }, setMetadata: async (instanceId, tableId, familyId) => { // [START bigtable_api_set_family_meta] - const {BigtableTableAdminClient, GCRuleMaker} = require('@google-cloud/bigtable').v2; + const {BigtableTableAdminClient, GCRuleMaker} = + require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); diff --git a/samples/api-reference-doc-snippets/table.js b/samples/api-reference-doc-snippets/table.js index 6ba023378..81c91f15f 100644 --- a/samples/api-reference-doc-snippets/table.js +++ b/samples/api-reference-doc-snippets/table.js @@ -340,15 +340,18 @@ const snippets = { // [END bigtable_api_sample_row_keys] }, - getIamPolicy: (instanceId, tableId) => { + getIamPolicy: async (instanceId, tableId) => { // [START bigtable_api_get_table_Iam_policy] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); - table - .getIamPolicy() + const request = { + resource: adminClient.tablePath(projectId, instanceId, tableId), + }; + + adminClient + .getIamPolicy(request) .then(result => { const policy = result[0]; }) @@ -358,12 +361,11 @@ const snippets = { // [END bigtable_api_get_table_Iam_policy] }, - setIamPolicy: (instanceId, tableId) => { + setIamPolicy: async (instanceId, tableId) => { // [START bigtable_api_set_table_Iam_policy] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); const policy = { bindings: [ @@ -374,8 +376,13 @@ const snippets = { ], }; - table - .setIamPolicy(policy) + const request = { + resource: adminClient.tablePath(projectId, instanceId, tableId), + policy: policy, + }; + + adminClient + .setIamPolicy(request) .then(result => { const setPolicy = result[0]; }) @@ -385,16 +392,21 @@ const snippets = { // [END bigtable_api_set_table_Iam_policy] }, - testIamPermissions: (instanceId, tableId) => { + testIamPermissions: async (instanceId, tableId) => { // [START bigtable_api_test_table_Iam_permissions] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const table = instance.table(tableId); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); const permissions = ['bigtable.tables.get', 'bigtable.tables.readRows']; - table - .testIamPermissions(permissions) + + const request = { + resource: adminClient.tablePath(projectId, instanceId, tableId), + permissions: permissions, + }; + + adminClient + .testIamPermissions(request) .then(result => { const grantedPermissions = result[0]; }) From 7241dbeb5099f9d4153ade5f2f34b3ec626de4fe Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Tue, 2 Sep 2025 17:28:04 -0400 Subject: [PATCH 39/96] correct the backups samples --- samples/test/backups.js | 93 +++++++++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 22 deletions(-) diff --git a/samples/test/backups.js b/samples/test/backups.js index 2919b61f1..2391c51d7 100644 --- a/samples/test/backups.js +++ b/samples/test/backups.js @@ -37,17 +37,36 @@ describe('backups', async () => { const backup = cluster.backup(BACKUP_ID); async function createTestBackup(backupId) { - const [backup, operation] = await cluster.createBackup(backupId, { - table, - expireTime: new Date(Date.now() + 60 * 60 * 1000), // 1 hour from now - }); - await operation.promise(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const request = { + parent: adminClient.clusterPath(projectId, INSTANCE_ID, CLUSTER_ID), + backupId: backupId, + backup: { + sourceTable: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + expireTime: new Date(Date.now() + 60 * 60 * 1000), // 1 hour from now + }, + }; + const [operation] = await adminClient.createBackup(request); + const [backup] = await operation.promise(); return backup; } before(async () => { - await table.create(); - await table.createFamily('follows'); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const request = { + parent: adminClient.instancePath(projectId, INSTANCE_ID), + tableId: TABLE_ID, + table: { + columnFamilies: { + follows: {}, + }, + }, + }; + await adminClient.createTable(request); await table.insert([ { key: 'alincoln', @@ -71,10 +90,15 @@ describe('backups', async () => { after(async () => { async function reapBackups(instance) { - const [backups] = await instance.getBackups(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const [backups] = await adminClient.listBackups({ + parent: adminClient.instancePath(projectId, instance.id), + }); return Promise.all( backups.map(backup => { - return backup.delete({timeout: 50 * 1000}); + return adminClient.deleteBackup({name: backup.name}); }), ); } @@ -103,8 +127,18 @@ describe('backups', async () => { }); it('should get an existing backup', async () => { - // Refresh our copy of the backup metadata. - const [metadata] = await backup.getMetadata(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const request = { + name: adminClient.backupPath( + projectId, + INSTANCE_ID, + CLUSTER_ID, + BACKUP_ID, + ), + }; + const [metadata] = await adminClient.getBackup(request); const stdout = execSync( `node ./backups.get.js ${INSTANCE_ID} ${TABLE_ID} ${CLUSTER_ID} ${BACKUP_ID}`, @@ -112,25 +146,25 @@ describe('backups', async () => { assert.include(stdout, `The backup is ${metadata.sizeBytes} bytes.`); assert.include( stdout, - `The backup will auto-delete at ${metadata.expireDate.toISOString()}`, + `The backup will auto-delete at ${new Date(metadata.expireTime.seconds * 1000).toISOString()}`, ); assert.include( stdout, - `The backup finished being created at ${metadata.endTime.toISOString()}`, + `The backup finished being created at ${new Date(metadata.endTime.seconds * 1000).toISOString()}`, ); }); it('should get existing backups', async () => { - const [backupsFromInstance] = await instance.listBackups(); - const [backupsFromCluster] = await cluster.listBackups(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const [backupsFromCluster] = await adminClient.listBackups({ + parent: adminClient.clusterPath(projectId, INSTANCE_ID, CLUSTER_ID), + }); const stdout = execSync( `node ./backups.list.js ${INSTANCE_ID} ${TABLE_ID} ${CLUSTER_ID}`, ); - assert.include( - stdout, - `${backupsFromInstance.length} backups returned from the instance.`, - ); assert.include( stdout, `${backupsFromCluster.length} backups returned from the cluster.`, @@ -149,18 +183,33 @@ describe('backups', async () => { const backupId = generateId(); const backup = await createTestBackup(backupId); - const oldExpireTime = backup.expireTime.toISOString(); + const oldExpireTime = new Date( + backup.expireTime.seconds * 1000, + ).toISOString(); const stdout = execSync( `node ./backups.update.js ${INSTANCE_ID} ${TABLE_ID} ${CLUSTER_ID} ${backupId}`, ); - const newExpireTime = backup.expireTime.toISOString(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const [updatedBackup] = await adminClient.getBackup({ + name: adminClient.backupPath( + projectId, + INSTANCE_ID, + CLUSTER_ID, + backupId, + ), + }); + const newExpireTime = new Date( + updatedBackup.expireTime.seconds * 1000, + ).toISOString(); assert.notStrictEqual(oldExpireTime, newExpireTime); assert.include( stdout, - `The backup will now auto-delete at ${backup.metadata.expireDate}.`, + `The backup will now auto-delete at ${newExpireTime}.`, ); }); }); From 9eb96e04990e489d32b910effcc93687c56f4537 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Tue, 2 Sep 2025 17:28:31 -0400 Subject: [PATCH 40/96] Revert "correct the backups samples" This reverts commit 7241dbeb5099f9d4153ade5f2f34b3ec626de4fe. --- samples/test/backups.js | 93 ++++++++++------------------------------- 1 file changed, 22 insertions(+), 71 deletions(-) diff --git a/samples/test/backups.js b/samples/test/backups.js index 2391c51d7..2919b61f1 100644 --- a/samples/test/backups.js +++ b/samples/test/backups.js @@ -37,36 +37,17 @@ describe('backups', async () => { const backup = cluster.backup(BACKUP_ID); async function createTestBackup(backupId) { - const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; - const adminClient = new BigtableTableAdminClient(); - const projectId = await adminClient.getProjectId(); - const request = { - parent: adminClient.clusterPath(projectId, INSTANCE_ID, CLUSTER_ID), - backupId: backupId, - backup: { - sourceTable: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), - expireTime: new Date(Date.now() + 60 * 60 * 1000), // 1 hour from now - }, - }; - const [operation] = await adminClient.createBackup(request); - const [backup] = await operation.promise(); + const [backup, operation] = await cluster.createBackup(backupId, { + table, + expireTime: new Date(Date.now() + 60 * 60 * 1000), // 1 hour from now + }); + await operation.promise(); return backup; } before(async () => { - const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; - const adminClient = new BigtableTableAdminClient(); - const projectId = await adminClient.getProjectId(); - const request = { - parent: adminClient.instancePath(projectId, INSTANCE_ID), - tableId: TABLE_ID, - table: { - columnFamilies: { - follows: {}, - }, - }, - }; - await adminClient.createTable(request); + await table.create(); + await table.createFamily('follows'); await table.insert([ { key: 'alincoln', @@ -90,15 +71,10 @@ describe('backups', async () => { after(async () => { async function reapBackups(instance) { - const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; - const adminClient = new BigtableTableAdminClient(); - const projectId = await adminClient.getProjectId(); - const [backups] = await adminClient.listBackups({ - parent: adminClient.instancePath(projectId, instance.id), - }); + const [backups] = await instance.getBackups(); return Promise.all( backups.map(backup => { - return adminClient.deleteBackup({name: backup.name}); + return backup.delete({timeout: 50 * 1000}); }), ); } @@ -127,18 +103,8 @@ describe('backups', async () => { }); it('should get an existing backup', async () => { - const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; - const adminClient = new BigtableTableAdminClient(); - const projectId = await adminClient.getProjectId(); - const request = { - name: adminClient.backupPath( - projectId, - INSTANCE_ID, - CLUSTER_ID, - BACKUP_ID, - ), - }; - const [metadata] = await adminClient.getBackup(request); + // Refresh our copy of the backup metadata. + const [metadata] = await backup.getMetadata(); const stdout = execSync( `node ./backups.get.js ${INSTANCE_ID} ${TABLE_ID} ${CLUSTER_ID} ${BACKUP_ID}`, @@ -146,25 +112,25 @@ describe('backups', async () => { assert.include(stdout, `The backup is ${metadata.sizeBytes} bytes.`); assert.include( stdout, - `The backup will auto-delete at ${new Date(metadata.expireTime.seconds * 1000).toISOString()}`, + `The backup will auto-delete at ${metadata.expireDate.toISOString()}`, ); assert.include( stdout, - `The backup finished being created at ${new Date(metadata.endTime.seconds * 1000).toISOString()}`, + `The backup finished being created at ${metadata.endTime.toISOString()}`, ); }); it('should get existing backups', async () => { - const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; - const adminClient = new BigtableTableAdminClient(); - const projectId = await adminClient.getProjectId(); - const [backupsFromCluster] = await adminClient.listBackups({ - parent: adminClient.clusterPath(projectId, INSTANCE_ID, CLUSTER_ID), - }); + const [backupsFromInstance] = await instance.listBackups(); + const [backupsFromCluster] = await cluster.listBackups(); const stdout = execSync( `node ./backups.list.js ${INSTANCE_ID} ${TABLE_ID} ${CLUSTER_ID}`, ); + assert.include( + stdout, + `${backupsFromInstance.length} backups returned from the instance.`, + ); assert.include( stdout, `${backupsFromCluster.length} backups returned from the cluster.`, @@ -183,33 +149,18 @@ describe('backups', async () => { const backupId = generateId(); const backup = await createTestBackup(backupId); - const oldExpireTime = new Date( - backup.expireTime.seconds * 1000, - ).toISOString(); + const oldExpireTime = backup.expireTime.toISOString(); const stdout = execSync( `node ./backups.update.js ${INSTANCE_ID} ${TABLE_ID} ${CLUSTER_ID} ${backupId}`, ); - const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; - const adminClient = new BigtableTableAdminClient(); - const projectId = await adminClient.getProjectId(); - const [updatedBackup] = await adminClient.getBackup({ - name: adminClient.backupPath( - projectId, - INSTANCE_ID, - CLUSTER_ID, - backupId, - ), - }); - const newExpireTime = new Date( - updatedBackup.expireTime.seconds * 1000, - ).toISOString(); + const newExpireTime = backup.expireTime.toISOString(); assert.notStrictEqual(oldExpireTime, newExpireTime); assert.include( stdout, - `The backup will now auto-delete at ${newExpireTime}.`, + `The backup will now auto-delete at ${backup.metadata.expireDate}.`, ); }); }); From 0d3a8613d977d9e82bbaaae5bf214bb67f32a5e5 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 3 Sep 2025 09:46:25 -0400 Subject: [PATCH 41/96] Modify the reads samples --- samples/test/reads.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/samples/test/reads.js b/samples/test/reads.js index 47bfe1fa9..6d2b9da02 100644 --- a/samples/test/reads.js +++ b/samples/test/reads.js @@ -34,9 +34,20 @@ describe('reads', async () => { const TIMESTAMP = new Date(2019, 5, 1); TIMESTAMP.setUTCHours(0); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const request = { + parent: adminClient.instancePath(projectId, INSTANCE_ID), + tableId: TABLE_ID, + table: { + columnFamilies: { + stats_summary: {}, + }, + }, + }; + await adminClient.createTable(request); table = instance.table(TABLE_ID); - await table.create(); - await table.createFamily('stats_summary'); const rowsToInsert = [ { From 72c1ee3ab03c55a7a110640600363b5f3939c5cd Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 3 Sep 2025 09:52:38 -0400 Subject: [PATCH 42/96] Update the functions script --- samples/test/functions.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/samples/test/functions.js b/samples/test/functions.js index e31e14790..2f10d5c90 100644 --- a/samples/test/functions.js +++ b/samples/test/functions.js @@ -40,11 +40,21 @@ describe('functions', async () => { let ffProc; before(async () => { + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const request = { + parent: adminClient.instancePath(projectId, INSTANCE_ID), + tableId: TABLE_ID, + table: { + columnFamilies: { + stats_summary: {}, + }, + }, + }; + await adminClient.createTable(request).catch(console.error); table = instance.table(TABLE_ID); - await table.create().catch(console.error); - await table.createFamily('stats_summary').catch(console.error); - const rowsToInsert = [ { key: 'phone#4c410523#20190501', From e54adf91f36de7b2485f2f947d55d62236205607 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 3 Sep 2025 10:53:45 -0400 Subject: [PATCH 43/96] Make separate column family creation calls This makes the test pass --- samples/test/filters.js | 45 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/samples/test/filters.js b/samples/test/filters.js index 18901afd3..2771e75cb 100644 --- a/samples/test/filters.js +++ b/samples/test/filters.js @@ -36,11 +36,40 @@ describe('filters', async () => { before(async () => { const instance = await obtainTestInstance(); INSTANCE_ID = instance.id; + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const request = { + parent: adminClient.instancePath(projectId, INSTANCE_ID), + tableId: TABLE_ID, + table: {}, + }; + await adminClient.createTable(request).catch(console.error); table = instance.table(TABLE_ID); - - await table.create().catch(console.error); - await table.createFamily('stats_summary').catch(console.error); - await table.createFamily('cell_plan').catch(console.error); + const modifyFamiliesReq = { + name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + modifications: [ + { + id: 'stats_summary', + create: {}, + }, + ], + }; + await adminClient + .modifyColumnFamilies(modifyFamiliesReq) + .catch(console.error); + const modifyFamiliesReq2 = { + name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + modifications: [ + { + id: 'cell_plan', + create: {}, + }, + ], + }; + await adminClient + .modifyColumnFamilies(modifyFamiliesReq2) + .catch(console.error); const rowsToInsert = [ { @@ -189,7 +218,13 @@ describe('filters', async () => { }); after(async () => { - await table.delete().catch(console.error); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const request = { + name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + }; + await adminClient.deleteTable(request).catch(console.error); }); it('should filter with row sample', async () => { From 9941155661493c7b7560afe5f1818902549677c4 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 3 Sep 2025 11:15:09 -0400 Subject: [PATCH 44/96] Fix the deletes sample changes --- samples/deleteSnippets.js | 31 ++++++++++++++++++++++---- samples/test/deletes.js | 46 ++++++++++++++++++++++++++++++++++----- 2 files changed, 67 insertions(+), 10 deletions(-) diff --git a/samples/deleteSnippets.js b/samples/deleteSnippets.js index abe448209..173985718 100644 --- a/samples/deleteSnippets.js +++ b/samples/deleteSnippets.js @@ -111,16 +111,39 @@ async function main( } case 'deleteColumnFamily': { // [START bigtable_delete_column_family] - const cf = table.family('stats_summary'); - await cf.delete(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const request = { + name: adminClient.tablePath(projectId, instanceId, tableId), + modifications: [ + { + id: 'stats_summary', + drop: true, + }, + ], + }; + await adminClient.modifyColumnFamilies(request); await printRows(); // [END bigtable_delete_column_family] break; } case 'deleteTable': { // [START bigtable_delete_table] - await table.delete(); - console.log(await table.exists({})); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const request = { + name: adminClient.tablePath(projectId, instanceId, tableId), + }; + await adminClient.deleteTable(request); + console.log( + await adminClient + .getTable({ + name: adminClient.tablePath(projectId, instanceId, tableId), + }) + .catch(e => (e.code === 5 ? false : e)), + ); // [END bigtable_delete_table] break; } diff --git a/samples/test/deletes.js b/samples/test/deletes.js index a41ed856d..1daf8047d 100644 --- a/samples/test/deletes.js +++ b/samples/test/deletes.js @@ -32,14 +32,48 @@ describe('deletes', async () => { before(async () => { const instance = await obtainTestInstance(); INSTANCE_ID = instance.id; - table = instance.table(TABLE_ID); - const tableExists = (await table.exists({}))[0]; + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const tableExists = await adminClient + .getTable({name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID)}) + .catch(e => (e.code === 5 ? false : e)); if (tableExists) { - await table.delete({}); + await adminClient.deleteTable({ + name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + }); } - await table.create(); - await table.createFamily('stats_summary'); - await table.createFamily('cell_plan'); + const request = { + parent: adminClient.instancePath(projectId, INSTANCE_ID), + tableId: TABLE_ID, + table: {}, + }; + await adminClient.createTable(request); + const modifyFamiliesReq = { + name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + modifications: [ + { + id: 'stats_summary', + create: {}, + }, + ], + }; + await adminClient + .modifyColumnFamilies(modifyFamiliesReq) + .catch(console.error); + const modifyFamiliesReq2 = { + name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + modifications: [ + { + id: 'cell_plan', + create: {}, + }, + ], + }; + await adminClient + .modifyColumnFamilies(modifyFamiliesReq2) + .catch(console.error); + table = instance.table(TABLE_ID); const rowsToInsert = [ { From 528480ab4fd3953ff5e66a63fafaaf0b5caf484c Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 3 Sep 2025 11:20:54 -0400 Subject: [PATCH 45/96] change the fixture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit don’t wrap the return value in brackets --- samples/__snapshots__/deletes.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/samples/__snapshots__/deletes.js b/samples/__snapshots__/deletes.js index 796485308..9887f9f70 100644 --- a/samples/__snapshots__/deletes.js +++ b/samples/__snapshots__/deletes.js @@ -177,7 +177,4 @@ exports['deletes should delete a column family 1'] = ` `; -exports['deletes should delete a table 1'] = ` -[ false ] - -`; +exports['deletes should delete a table 1'] = 'false'; From 1ed6a726703a0bc86c7c8f3d10ea66fde2bf6528 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 3 Sep 2025 11:23:48 -0400 Subject: [PATCH 46/96] return value should be false literal --- samples/__snapshots__/deletes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/__snapshots__/deletes.js b/samples/__snapshots__/deletes.js index 9887f9f70..c8c702cab 100644 --- a/samples/__snapshots__/deletes.js +++ b/samples/__snapshots__/deletes.js @@ -177,4 +177,4 @@ exports['deletes should delete a column family 1'] = ` `; -exports['deletes should delete a table 1'] = 'false'; +exports['deletes should delete a table 1'] = false; From b39fd455443d001dc04c366067d91a07f1095801 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 3 Sep 2025 11:33:36 -0400 Subject: [PATCH 47/96] Correct the fixture for the deletes samples --- samples/__snapshots__/deletes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/__snapshots__/deletes.js b/samples/__snapshots__/deletes.js index c8c702cab..ce4587cd8 100644 --- a/samples/__snapshots__/deletes.js +++ b/samples/__snapshots__/deletes.js @@ -177,4 +177,4 @@ exports['deletes should delete a column family 1'] = ` `; -exports['deletes should delete a table 1'] = false; +exports['deletes should delete a table 1'] = 'false\n'; From e9852094c9771be55f3f522eb4ea7b67ecbb8ea3 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 3 Sep 2025 13:35:26 -0400 Subject: [PATCH 48/96] Reintroduce the backup samples --- samples/test/backups.js | 101 +++++++++++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 22 deletions(-) diff --git a/samples/test/backups.js b/samples/test/backups.js index 2919b61f1..f708768bb 100644 --- a/samples/test/backups.js +++ b/samples/test/backups.js @@ -37,17 +37,44 @@ describe('backups', async () => { const backup = cluster.backup(BACKUP_ID); async function createTestBackup(backupId) { - const [backup, operation] = await cluster.createBackup(backupId, { - table, - expireTime: new Date(Date.now() + 60 * 60 * 1000), // 1 hour from now - }); - await operation.promise(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const request = { + parent: adminClient.clusterPath(projectId, INSTANCE_ID, CLUSTER_ID), + backupId: backupId, + backup: { + sourceTable: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + expireTime: new Date(Date.now() + 60 * 60 * 1000), // 1 hour from now + }, + }; + const [operation] = await adminClient.createBackup(request); + const [backup] = await operation.promise(); return backup; } before(async () => { - await table.create(); - await table.createFamily('follows'); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const request = { + parent: adminClient.instancePath(projectId, INSTANCE_ID), + tableId: TABLE_ID, + table: {}, + }; + await adminClient.createTable(request); + const modifyFamiliesReq = { + name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + modifications: [ + { + id: 'follows', + create: {}, + }, + ], + }; + await adminClient + .modifyColumnFamilies(modifyFamiliesReq) + .catch(console.error); await table.insert([ { key: 'alincoln', @@ -71,10 +98,15 @@ describe('backups', async () => { after(async () => { async function reapBackups(instance) { - const [backups] = await instance.getBackups(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const [backups] = await adminClient.listBackups({ + parent: `${adminClient.instancePath(projectId, instance.id)}/clusters/-`, + }); return Promise.all( backups.map(backup => { - return backup.delete({timeout: 50 * 1000}); + return adminClient.deleteBackup({name: backup.name}); }), ); } @@ -103,8 +135,18 @@ describe('backups', async () => { }); it('should get an existing backup', async () => { - // Refresh our copy of the backup metadata. - const [metadata] = await backup.getMetadata(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const request = { + name: adminClient.backupPath( + projectId, + INSTANCE_ID, + CLUSTER_ID, + BACKUP_ID, + ), + }; + const [metadata] = await adminClient.getBackup(request); const stdout = execSync( `node ./backups.get.js ${INSTANCE_ID} ${TABLE_ID} ${CLUSTER_ID} ${BACKUP_ID}`, @@ -112,25 +154,25 @@ describe('backups', async () => { assert.include(stdout, `The backup is ${metadata.sizeBytes} bytes.`); assert.include( stdout, - `The backup will auto-delete at ${metadata.expireDate.toISOString()}`, + `The backup will auto-delete at ${new Date(metadata.expireTime.seconds * 1000).toISOString()}`, ); assert.include( stdout, - `The backup finished being created at ${metadata.endTime.toISOString()}`, + `The backup finished being created at ${new Date(metadata.endTime.seconds * 1000).toISOString()}`, ); }); it('should get existing backups', async () => { - const [backupsFromInstance] = await instance.listBackups(); - const [backupsFromCluster] = await cluster.listBackups(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const [backupsFromCluster] = await adminClient.listBackups({ + parent: adminClient.clusterPath(projectId, INSTANCE_ID, CLUSTER_ID), + }); const stdout = execSync( `node ./backups.list.js ${INSTANCE_ID} ${TABLE_ID} ${CLUSTER_ID}`, ); - assert.include( - stdout, - `${backupsFromInstance.length} backups returned from the instance.`, - ); assert.include( stdout, `${backupsFromCluster.length} backups returned from the cluster.`, @@ -149,18 +191,33 @@ describe('backups', async () => { const backupId = generateId(); const backup = await createTestBackup(backupId); - const oldExpireTime = backup.expireTime.toISOString(); + const oldExpireTime = new Date( + backup.expireTime.seconds * 1000, + ).toISOString(); const stdout = execSync( `node ./backups.update.js ${INSTANCE_ID} ${TABLE_ID} ${CLUSTER_ID} ${backupId}`, ); - const newExpireTime = backup.expireTime.toISOString(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const [updatedBackup] = await adminClient.getBackup({ + name: adminClient.backupPath( + projectId, + INSTANCE_ID, + CLUSTER_ID, + backupId, + ), + }); + const newExpireTime = new Date( + updatedBackup.expireTime.seconds * 1000, + ).toISOString(); assert.notStrictEqual(oldExpireTime, newExpireTime); assert.include( stdout, - `The backup will now auto-delete at ${backup.metadata.expireDate}.`, + `The backup will now auto-delete at ${newExpireTime}.`, ); }); }); From c6ed0cf96393827d7e3e48b4d0f764f1388c7353 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Fri, 29 Aug 2025 14:09:06 -0400 Subject: [PATCH 49/96] Replace write.js code with calls to generated layr --- samples/test/write.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/samples/test/write.js b/samples/test/write.js index efd3d9a45..e874e6d8a 100644 --- a/samples/test/write.js +++ b/samples/test/write.js @@ -31,10 +31,20 @@ describe('writes', async () => { const instance = await obtainTestInstance(); INSTANCE_ID = instance.id; + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + const request = { + parent: adminClient.instancePath(projectId, INSTANCE_ID), + tableId: TABLE_ID, + table: { + columnFamilies: { + stats_summary: {}, + }, + }, + }; + await adminClient.createTable(request).catch(console.error); table = instance.table(TABLE_ID); - - await table.create().catch(console.error); - await table.createFamily('stats_summary').catch(console.error); }); it('should do a simple write', async () => { From 2b6a378315075e7d7ac8f0400e215ddd35a1aedd Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Fri, 29 Aug 2025 14:11:00 -0400 Subject: [PATCH 50/96] removed unused table --- samples/test/write.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/samples/test/write.js b/samples/test/write.js index e874e6d8a..88b6ecdeb 100644 --- a/samples/test/write.js +++ b/samples/test/write.js @@ -25,7 +25,6 @@ const TABLE_ID = `mobile-time-series-${uuid.v4()}`.substr(0, 30); // Bigtable na describe('writes', async () => { let INSTANCE_ID; - let table; before(async () => { const instance = await obtainTestInstance(); @@ -44,7 +43,6 @@ describe('writes', async () => { }, }; await adminClient.createTable(request).catch(console.error); - table = instance.table(TABLE_ID); }); it('should do a simple write', async () => { From f88db1a498105e788e0788a1303b4f0f7f0296a3 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Fri, 29 Aug 2025 14:46:56 -0400 Subject: [PATCH 51/96] backups from instance as well --- samples/test/backups.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/samples/test/backups.js b/samples/test/backups.js index f708768bb..c59c90a7a 100644 --- a/samples/test/backups.js +++ b/samples/test/backups.js @@ -166,13 +166,16 @@ describe('backups', async () => { const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); - const [backupsFromCluster] = await adminClient.listBackups({ - parent: adminClient.clusterPath(projectId, INSTANCE_ID, CLUSTER_ID), - }); + const [backupsFromInstance] = await adminClient.listBackups({parent: adminClient.instancePath(projectId, INSTANCE_ID)}); + const [backupsFromCluster] = await adminClient.listBackups({parent: adminClient.clusterPath(projectId, INSTANCE_ID, CLUSTER_ID)}); const stdout = execSync( `node ./backups.list.js ${INSTANCE_ID} ${TABLE_ID} ${CLUSTER_ID}`, ); + assert.include( + stdout, + `${backupsFromInstance.length} backups returned from the instance.`, + ); assert.include( stdout, `${backupsFromCluster.length} backups returned from the cluster.`, From 1ca6cf0329a84c0f5aca6061f03227c404acec5a Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 3 Sep 2025 14:08:43 -0400 Subject: [PATCH 52/96] Fix the index.js sample --- samples/hello-world/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/hello-world/index.js b/samples/hello-world/index.js index 41e2b6657..52cf15092 100644 --- a/samples/hello-world/index.js +++ b/samples/hello-world/index.js @@ -44,6 +44,7 @@ const getRowGreeting = row => { // [START bigtable_hw_connect] const bigtableClient = new Bigtable(); const instance = bigtableClient.instance(INSTANCE_ID); + const table = instance.table(TABLE_ID); // [END bigtable_hw_connect] // [START bigtable_hw_create_table] @@ -53,7 +54,9 @@ const getRowGreeting = row => { let tableExists = true; try { - await adminClient.getTable({name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID)}); + await adminClient.getTable({ + name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + }); } catch (e) { if (e.code === 5) { tableExists = false; @@ -137,9 +140,6 @@ const getRowGreeting = row => { // [START bigtable_hw_delete_table] console.log('Delete the table'); - const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; - const adminClient = new BigtableTableAdminClient(); - const projectId = await adminClient.getProjectId(); const request = { name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), }; From 1c8ed0b914e746bf7a2e87b3baa73e74fee55ca7 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 3 Sep 2025 14:28:07 -0400 Subject: [PATCH 53/96] Fixed a bunch of syntax highlighting errors --- samples/tableadmin.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/samples/tableadmin.js b/samples/tableadmin.js index 0b7f159de..e7f5f6ac9 100644 --- a/samples/tableadmin.js +++ b/samples/tableadmin.js @@ -72,7 +72,10 @@ async function runTableOperations(instanceID, tableID) { const options = { view: 'id', }; - const [tableMetadata] = await adminClient.getTable({name: table.name, view: options.view}); + const [tableMetadata] = await adminClient.getTable({ + name: table.name, + view: options.view, + }); console.log(`Metadata: ${JSON.stringify(tableMetadata)}`); // [END bigtable_get_table_metadata] @@ -230,8 +233,11 @@ async function runTableOperations(instanceID, tableID) { console.log('Printing ID and GC Rule for all column families...'); // [START bigtable_list_column_families] // List all families in the table with GC rules - const [tableData] = await adminClient.getTable({name: table.name, view: 'FULL'}); - const families = tableData.columnFamilies; + const [tableData2] = await adminClient.getTable({ + name: table.name, + view: 'FULL', + }); + const families = tableData2.columnFamilies; // Print ID, GC Rule for each column family for (const familyId in families) { const family = families[familyId]; @@ -272,7 +278,10 @@ async function runTableOperations(instanceID, tableID) { console.log('\nPrint updated column family cf1 GC rule...'); // [START bigtable_family_get_gc_rule] // Retrieve column family metadata (Id, column family GC rule) - const [tableData] = await adminClient.getTable({name: table.name, view: 'FULL'}); + const [tableData] = await adminClient.getTable({ + name: table.name, + view: 'FULL', + }); const metadata = tableData.columnFamilies['cf1'].gcRule; console.log(`Metadata: ${JSON.stringify(metadata)}`); // [END bigtable_family_get_gc_rule] @@ -305,7 +314,9 @@ async function deleteTable(instanceID, tableID) { // [START bigtable_delete_table] // Delete the entire table console.log('Delete the table.'); - await adminClient.deleteTable({name: adminClient.tablePath(projectId, instanceID, tableID)}); + await adminClient.deleteTable({ + name: adminClient.tablePath(projectId, instanceID, tableID), + }); console.log(`Table deleted: ${tableID}`); // [END bigtable_delete_table] } From 03a5619a069f13737e9b5b36081c18148a0a28e8 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 3 Sep 2025 15:39:38 -0400 Subject: [PATCH 54/96] run the linter --- samples/test/backups.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/samples/test/backups.js b/samples/test/backups.js index c59c90a7a..70f2f29cd 100644 --- a/samples/test/backups.js +++ b/samples/test/backups.js @@ -166,8 +166,12 @@ describe('backups', async () => { const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); - const [backupsFromInstance] = await adminClient.listBackups({parent: adminClient.instancePath(projectId, INSTANCE_ID)}); - const [backupsFromCluster] = await adminClient.listBackups({parent: adminClient.clusterPath(projectId, INSTANCE_ID, CLUSTER_ID)}); + const [backupsFromInstance] = await adminClient.listBackups({ + parent: adminClient.instancePath(projectId, INSTANCE_ID), + }); + const [backupsFromCluster] = await adminClient.listBackups({ + parent: adminClient.clusterPath(projectId, INSTANCE_ID, CLUSTER_ID), + }); const stdout = execSync( `node ./backups.list.js ${INSTANCE_ID} ${TABLE_ID} ${CLUSTER_ID}`, From b5deee61cc331fcd4965d2621f91a2033f1a4328 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 3 Sep 2025 15:53:44 -0400 Subject: [PATCH 55/96] Changes to pass the linting check --- samples/api-reference-doc-snippets/family.js | 5 ++++- samples/test/backups.js | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/samples/api-reference-doc-snippets/family.js b/samples/api-reference-doc-snippets/family.js index aad38aa92..a93950141 100644 --- a/samples/api-reference-doc-snippets/family.js +++ b/samples/api-reference-doc-snippets/family.js @@ -54,7 +54,10 @@ const snippets = { try { const [table] = await adminClient.getTable(request); - const exists = table.columnFamilies.hasOwnProperty(familyId); + const exists = Object.prototype.hasOwnProperty.call( + table.columnFamilies, + familyId, + ); console.log(`Family ${familyId} exists: ${exists}`); } catch (err) { // Handle the error. diff --git a/samples/test/backups.js b/samples/test/backups.js index 70f2f29cd..62be72279 100644 --- a/samples/test/backups.js +++ b/samples/test/backups.js @@ -34,7 +34,6 @@ describe('backups', async () => { const table = instance.table(TABLE_ID); const cluster = instance.cluster(INSTANCE_ID); - const backup = cluster.backup(BACKUP_ID); async function createTestBackup(backupId) { const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; From 7553201c337073fe68c0e73cad640d13692aab2a Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 4 Sep 2025 11:24:40 -0400 Subject: [PATCH 56/96] Eliminate unused cluster --- samples/test/backups.js | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/test/backups.js b/samples/test/backups.js index 62be72279..f4f69cbb5 100644 --- a/samples/test/backups.js +++ b/samples/test/backups.js @@ -33,7 +33,6 @@ describe('backups', async () => { const CLUSTER_ID = instance.id; // The test function uses the same name. const table = instance.table(TABLE_ID); - const cluster = instance.cluster(INSTANCE_ID); async function createTestBackup(backupId) { const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; From 98f1abcd2cfc9be0be61909467ac4edb69de6d6f Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 4 Sep 2025 14:40:32 -0400 Subject: [PATCH 57/96] Add comment for restore table LRO --- samples/api-reference-doc-snippets/backups.restore.js | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/api-reference-doc-snippets/backups.restore.js b/samples/api-reference-doc-snippets/backups.restore.js index 530813683..3fab54738 100644 --- a/samples/api-reference-doc-snippets/backups.restore.js +++ b/samples/api-reference-doc-snippets/backups.restore.js @@ -45,6 +45,7 @@ async function main( ), }); + // The following call is part of the restoreTable long running operation. const [table] = await operation.promise(); console.log(`Table restored to ${table.name} successfully.`); From a6faac9456e5d227b24a56785c401d92c0eded0f Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 4 Sep 2025 15:30:44 -0400 Subject: [PATCH 58/96] Add a script for the consistency token --- samples/api-reference-doc-snippets/table.js | 33 +++++++++++++++++++++ samples/test/table.js | 4 +++ 2 files changed, 37 insertions(+) diff --git a/samples/api-reference-doc-snippets/table.js b/samples/api-reference-doc-snippets/table.js index 81c91f15f..4af9b4906 100644 --- a/samples/api-reference-doc-snippets/table.js +++ b/samples/api-reference-doc-snippets/table.js @@ -452,6 +452,39 @@ const snippets = { }); // [END bigtable_api_del_table] }, + consistency: async (instanceId, tableId) => { + // [START bigtable_api_consistency] + try { + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const projectId = await adminClient.getProjectId(); + // 1. Generate a consistency token. + const token = ( + await adminClient.generateConsistencyToken({ + name: adminClient.tablePath(projectId, instanceId, tableId), + }) + )[0].consistencyToken; + console.log('Generated consistency token:', token); + let isConsistent = false; + while (!isConsistent) { + // 2. Check for consistency + const [consistent] = adminClient.checkConsistency({ + name: adminClient.tablePath(projectId, instanceId, tableId), + consistencyToken: token, + }); + isConsistent = consistent; + + if (isConsistent) { + console.log('Data is consistent!'); + } else { + console.log('Data is not yet consistent. Retrying in 5 seconds...'); + } + } + } catch (e) { + // Handle the error. + } + // [END bigtable_api_consistency] + }, }; module.exports = snippets; diff --git a/samples/test/table.js b/samples/test/table.js index 9aa0cc4c3..414230a11 100644 --- a/samples/test/table.js +++ b/samples/test/table.js @@ -101,4 +101,8 @@ describe.skip('Table Snippets', () => { it('should delete table', () => { tableSnippets.delTable(INSTANCE_ID, TABLE_ID); }); + + it('should check consistency', () => { + tableSnippets.consistency(INSTANCE_ID, TABLE_ID); + }); }); From f71dc27b692ff16330b890c226dd5d2d60c18f11 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 4 Sep 2025 13:30:54 -0400 Subject: [PATCH 59/96] Use instance admin client and eliminate unused variables --- samples/test/app-profile.js | 55 +++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/samples/test/app-profile.js b/samples/test/app-profile.js index aa76ff435..2c7b3f7aa 100644 --- a/samples/test/app-profile.js +++ b/samples/test/app-profile.js @@ -16,8 +16,6 @@ const uuid = require('uuid'); const {describe, it, before, after} = require('mocha'); -const {Bigtable} = require('@google-cloud/bigtable'); -const bigtable = new Bigtable(); const INSTANCE_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules const CLUSTER_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules @@ -25,30 +23,47 @@ const APP_PROFILE_ID = 'my-app-profile'; const appProfileSnippets = require('./app-profile.js'); -const instance = bigtable.instance(INSTANCE_ID); - describe.skip('App Profile Snippets', () => { before(async () => { - const [, operation] = await instance.create({ - clusters: [ - { - name: CLUSTER_ID, - location: 'us-central1-f', - storage: 'hdd', + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + const request = { + parent: instanceAdminClient.projectPath(projectId), + instanceId: INSTANCE_ID, + instance: { + displayName: INSTANCE_ID, + labels: {}, + type: 'DEVELOPMENT', + }, + clusters: { + [CLUSTER_ID]: { + location: instanceAdminClient.locationPath( + projectId, + 'us-central1-f', + ), + serveNodes: 1, + defaultStorageType: 'HDD', }, - ], - type: 'DEVELOPMENT', - }); + }, + }; + const [, operation] = await instanceAdminClient.createInstance(request); await operation.promise(); }); - after(() => { - instance.exists().then(result => { - const exists = result[0]; - if (exists) { - instance.delete(); - } - }); + after(async () => { + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + const instancePath = instanceAdminClient.instancePath( + projectId, + INSTANCE_ID, + ); + try { + await instanceAdminClient.deleteInstance({name: instancePath}); + } catch (err) { + // Handle the error. + } }); it('should create an app-profile', () => { From 1f3f203129f8925f3d1ef9be633cd6d0e64e9553 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 4 Sep 2025 13:45:03 -0400 Subject: [PATCH 60/96] Make a separate modifyColumnFamilies call --- samples/test/write.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/samples/test/write.js b/samples/test/write.js index 88b6ecdeb..16e85a4be 100644 --- a/samples/test/write.js +++ b/samples/test/write.js @@ -36,13 +36,19 @@ describe('writes', async () => { const request = { parent: adminClient.instancePath(projectId, INSTANCE_ID), tableId: TABLE_ID, - table: { - columnFamilies: { - stats_summary: {}, - }, - }, + table: {}, }; await adminClient.createTable(request).catch(console.error); + const modifyFamiliesReq = { + name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + modifications: [ + { + id: 'stats_summary', + create: {}, + }, + ], + }; + await adminClient.modifyColumnFamilies(modifyFamiliesReq).catch(console.error); }); it('should do a simple write', async () => { From 27ef71f4086e00b115f2c5f261cddf1783ef653e Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 4 Sep 2025 14:11:44 -0400 Subject: [PATCH 61/96] Use instance admin client for the clusters samples --- samples/test/cluster.js | 43 ++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/samples/test/cluster.js b/samples/test/cluster.js index aeb7f3234..cde297c67 100644 --- a/samples/test/cluster.js +++ b/samples/test/cluster.js @@ -28,29 +28,36 @@ const instance = bigtable.instance(INSTANCE_ID); describe.skip('Cluster Snippets', () => { before(async () => { - try { - const [, operation] = await instance.create({ - clusters: [ - { - name: CLUSTER_ID, - location: 'us-central1-f', - storage: 'hdd', - }, - ], + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + const request = { + parent: instanceAdminClient.projectPath(projectId), + instanceId: INSTANCE_ID, + instance: { + displayName: INSTANCE_ID, + labels: {}, type: 'DEVELOPMENT', - }); - await operation.promise(); - } catch (err) { - // Handle the error. - } + }, + clusters: { + [CLUSTER_ID]: { + location: instanceAdminClient.locationPath(projectId, 'us-central1-f'), + serveNodes: 1, + defaultStorageType: 'HDD', + }, + }, + }; + const [, operation] = await instanceAdminClient.createInstance(request); + await operation.promise(); }); after(async () => { + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + const instancePath = instanceAdminClient.instancePath(projectId, INSTANCE_ID); try { - const [exists] = await instance.exists(); - if (exists) { - await instance.delete(); - } + await instanceAdminClient.deleteInstance({name: instancePath}); } catch (err) { // Handle the error. } From 7ce5fa6b40f5c666d745f0ee4c4f6b8b57e4d3bc Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 4 Sep 2025 16:09:02 -0400 Subject: [PATCH 62/96] use admin client in family.js --- samples/test/family.js | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/samples/test/family.js b/samples/test/family.js index 24811a458..f44418b6f 100644 --- a/samples/test/family.js +++ b/samples/test/family.js @@ -31,21 +31,30 @@ const instance = bigtable.instance(INSTANCE_ID); describe.skip('Family Snippets', () => { before(async () => { try { - const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; - const [, operation] = await instance.create({ - clusters: [ - { - name: CLUSTER_ID, - location: 'us-central1-f', - storage: 'hdd', + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + const request = { + parent: instanceAdminClient.projectPath(projectId), + instanceId: INSTANCE_ID, + instance: { + displayName: INSTANCE_ID, + labels: {}, + type: 'DEVELOPMENT', + }, + clusters: { + [CLUSTER_ID]: { + location: instanceAdminClient.locationPath(projectId, 'us-central1-f'), + serveNodes: 1, + defaultStorageType: 'HDD', }, - ], - type: 'DEVELOPMENT', - }); + }, + }; + const [, operation] = await instanceAdminClient.createInstance(request); await operation.promise(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); - const projectId = await adminClient.getProjectId(); - const request = { + const tableRequest = { parent: adminClient.instancePath(projectId, INSTANCE_ID), tableId: TABLE_ID, table: { @@ -54,7 +63,7 @@ describe.skip('Family Snippets', () => { }, }, }; - await adminClient.createTable(request); + await adminClient.createTable(tableRequest); } catch (err) { // } @@ -62,7 +71,11 @@ describe.skip('Family Snippets', () => { after(async () => { try { - await instance.delete(); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + const instancePath = instanceAdminClient.instancePath(projectId, INSTANCE_ID); + await instanceAdminClient.deleteInstance({name: instancePath}); } catch (err) { // Handle the error. } From c265cf49abc9a09787b37a94fd57fa137dd5a3ae Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 4 Sep 2025 16:21:34 -0400 Subject: [PATCH 63/96] Use the instance admin client for creating instanc --- samples/test/util.js | 46 +++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/samples/test/util.js b/samples/test/util.js index 5814accb4..eee6867bc 100644 --- a/samples/test/util.js +++ b/samples/test/util.js @@ -13,14 +13,8 @@ // limitations under the License. const uuid = require('uuid'); -const {Bigtable} = require('@google-cloud/bigtable'); -const {after} = require('mocha'); - -const PREFIX = 'gcloud-tests-'; -const runId = uuid.v4().split('-')[0]; -const instanceId = `${PREFIX}-${runId}`; -const clusterId = `${PREFIX}-${runId}`; -const bigtable = new Bigtable(); +const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; +const instanceAdminClient = new BigtableInstanceAdminClient(); let instance; let obtainPromise; @@ -34,7 +28,7 @@ function generateId() { * Get instances created more than one hour ago. */ async function getStaleInstances() { - const [instances] = await bigtable.getInstances(); + const [instances] = await instanceAdminClient.listInstances(); return instances .filter(i => i.id.match(PREFIX)) .filter(i => { @@ -62,28 +56,36 @@ async function obtainTestInstance() { * Create a testing cluster and the corresponding instance. */ async function createTestInstance() { - instance = bigtable.instance(instanceId); - const [, operation] = await instance.create({ - clusters: [ - { - id: clusterId, - location: 'us-central1-c', - nodes: 3, + const projectId = await instanceAdminClient.getProjectId(); + const request = { + parent: instanceAdminClient.projectPath(projectId), + instanceId: instanceId, + instance: { + displayName: instanceId, + labels: { + time_created: Date.now(), + }, + }, + clusters: { + [clusterId]: { + location: instanceAdminClient.locationPath(projectId, 'us-central1-c'), + serveNodes: 1, + defaultStorageType: 'HDD', }, - ], - labels: { - time_created: Date.now(), }, - }); + }; + const [, operation] = await instanceAdminClient.createInstance(request); await operation.promise(); - return instance; + return instanceAdminClient.getInstance({name: instanceAdminClient.instancePath(projectId, instanceId)}); } /** * Delete the instance in a global hook. */ after(async () => { - await instance.delete(); + const projectId = await instanceAdminClient.getProjectId(); + const instancePath = instanceAdminClient.instancePath(projectId, instanceId); + await instanceAdminClient.deleteInstance({name: instancePath}); }); module.exports = {generateId, getStaleInstances, obtainTestInstance}; From f7dc2afbacd78655e20a77b2b3a1f41a1b2f5ae1 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Fri, 5 Sep 2025 15:21:43 -0400 Subject: [PATCH 64/96] reintroduce necessary variables --- samples/test/util.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/samples/test/util.js b/samples/test/util.js index eee6867bc..d005ea582 100644 --- a/samples/test/util.js +++ b/samples/test/util.js @@ -13,9 +13,15 @@ // limitations under the License. const uuid = require('uuid'); +const {after} = require('mocha'); + +const PREFIX = 'gcloud-tests-'; +const runId = uuid.v4().split('-')[0]; +const instanceId = `${PREFIX}-${runId}`; +const clusterId = `${PREFIX}-${runId}`; + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; const instanceAdminClient = new BigtableInstanceAdminClient(); -let instance; let obtainPromise; @@ -76,7 +82,9 @@ async function createTestInstance() { }; const [, operation] = await instanceAdminClient.createInstance(request); await operation.promise(); - return instanceAdminClient.getInstance({name: instanceAdminClient.instancePath(projectId, instanceId)}); + return instanceAdminClient.getInstance({ + name: instanceAdminClient.instancePath(projectId, instanceId), + }); } /** From e45ad3ff87dc66f0164d62fd08cecc838fee5924 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Tue, 9 Sep 2025 10:56:57 -0400 Subject: [PATCH 65/96] Fix the runtime issues from the before hook --- samples/test/deletes.js | 21 +++++++++++++-------- samples/test/util.js | 6 ++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/samples/test/deletes.js b/samples/test/deletes.js index 1daf8047d..c7cd2dff6 100644 --- a/samples/test/deletes.js +++ b/samples/test/deletes.js @@ -19,38 +19,42 @@ const snapshot = require('snap-shot-it'); const {describe, it, before} = require('mocha'); const cp = require('child_process'); const {obtainTestInstance} = require('./util'); +const {Bigtable} = require('@google-cloud/bigtable'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const TABLE_ID = `mobile-time-series-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules describe('deletes', async () => { + const bigtable = new Bigtable(); let table; let INSTANCE_ID; const TIMESTAMP = new Date(2019, 5, 1); TIMESTAMP.setUTCHours(0); before(async () => { - const instance = await obtainTestInstance(); - INSTANCE_ID = instance.id; + const [instance] = await obtainTestInstance(); + INSTANCE_ID = instance.displayName; const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); + const instancePath = `projects/${projectId}/instances/${INSTANCE_ID}`; + const tablePath = `${instancePath}/tables/${TABLE_ID}`; const tableExists = await adminClient - .getTable({name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID)}) + .getTable({name: tablePath}) .catch(e => (e.code === 5 ? false : e)); if (tableExists) { await adminClient.deleteTable({ - name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + name: tablePath, }); } const request = { - parent: adminClient.instancePath(projectId, INSTANCE_ID), + parent: instancePath, tableId: TABLE_ID, table: {}, }; await adminClient.createTable(request); const modifyFamiliesReq = { - name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + name: tablePath, modifications: [ { id: 'stats_summary', @@ -62,7 +66,7 @@ describe('deletes', async () => { .modifyColumnFamilies(modifyFamiliesReq) .catch(console.error); const modifyFamiliesReq2 = { - name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + name: tablePath, modifications: [ { id: 'cell_plan', @@ -73,7 +77,8 @@ describe('deletes', async () => { await adminClient .modifyColumnFamilies(modifyFamiliesReq2) .catch(console.error); - table = instance.table(TABLE_ID); + const handwrittenInstance = bigtable.instance(INSTANCE_ID); + table = handwrittenInstance.table(TABLE_ID); const rowsToInsert = [ { diff --git a/samples/test/util.js b/samples/test/util.js index d005ea582..8b74395b7 100644 --- a/samples/test/util.js +++ b/samples/test/util.js @@ -21,6 +21,7 @@ const instanceId = `${PREFIX}-${runId}`; const clusterId = `${PREFIX}-${runId}`; const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); let obtainPromise; @@ -63,6 +64,7 @@ async function obtainTestInstance() { */ async function createTestInstance() { const projectId = await instanceAdminClient.getProjectId(); + const location = 'us-central1-c'; const request = { parent: instanceAdminClient.projectPath(projectId), instanceId: instanceId, @@ -74,13 +76,13 @@ async function createTestInstance() { }, clusters: { [clusterId]: { - location: instanceAdminClient.locationPath(projectId, 'us-central1-c'), + location: `projects/${projectId}/locations/${location}`, serveNodes: 1, defaultStorageType: 'HDD', }, }, }; - const [, operation] = await instanceAdminClient.createInstance(request); + const [operation] = await instanceAdminClient.createInstance(request); await operation.promise(); return instanceAdminClient.getInstance({ name: instanceAdminClient.instancePath(projectId, instanceId), From ec006140e2c667328df5b5d3ea98ae8eae0d0fe4 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Tue, 9 Sep 2025 11:35:22 -0400 Subject: [PATCH 66/96] Fix bugs due to switch to admin layer --- samples/test/filters.js | 17 +++++++++++------ samples/test/reads.js | 12 ++++++++---- samples/test/write.js | 14 +++++++++----- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/samples/test/filters.js b/samples/test/filters.js index 2771e75cb..b18eef8be 100644 --- a/samples/test/filters.js +++ b/samples/test/filters.js @@ -20,12 +20,14 @@ const {assert} = require('chai'); const {describe, it, before, after} = require('mocha'); const cp = require('child_process'); const {obtainTestInstance} = require('./util'); +const {Bigtable} = require('@google-cloud/bigtable'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const runId = uuid.v4().split('-')[0]; const TABLE_ID = `mobile-time-series-${runId}`; describe('filters', async () => { + const bigtable = new Bigtable(); let table; let INSTANCE_ID; const TIMESTAMP = new Date(2019, 5, 1); @@ -34,20 +36,23 @@ describe('filters', async () => { TIMESTAMP_OLDER.setUTCHours(0); before(async () => { - const instance = await obtainTestInstance(); - INSTANCE_ID = instance.id; + const [instance] = await obtainTestInstance(); + INSTANCE_ID = instance.displayName; const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); + const instancePath = `projects/${projectId}/instances/${INSTANCE_ID}`; + const tablePath = `${instancePath}/tables/${TABLE_ID}`; const request = { - parent: adminClient.instancePath(projectId, INSTANCE_ID), + parent: instancePath, tableId: TABLE_ID, table: {}, }; await adminClient.createTable(request).catch(console.error); - table = instance.table(TABLE_ID); + const handwrittenInstance = bigtable.instance(INSTANCE_ID); + table = handwrittenInstance.table(TABLE_ID); const modifyFamiliesReq = { - name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + name: tablePath, modifications: [ { id: 'stats_summary', @@ -59,7 +64,7 @@ describe('filters', async () => { .modifyColumnFamilies(modifyFamiliesReq) .catch(console.error); const modifyFamiliesReq2 = { - name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + name: tablePath, modifications: [ { id: 'cell_plan', diff --git a/samples/test/reads.js b/samples/test/reads.js index 6d2b9da02..ee43157e3 100644 --- a/samples/test/reads.js +++ b/samples/test/reads.js @@ -19,17 +19,19 @@ const snapshot = require('snap-shot-it'); const {describe, it, before} = require('mocha'); const cp = require('child_process'); const {obtainTestInstance} = require('./util'); +const {Bigtable} = require('@google-cloud/bigtable'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const TABLE_ID = `mobile-time-series-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules describe('reads', async () => { + const bigtable = new Bigtable(); let INSTANCE_ID; let table; before(async () => { - const instance = await obtainTestInstance(); - INSTANCE_ID = instance.id; + const [instance] = await obtainTestInstance(); + INSTANCE_ID = instance.displayName; const TIMESTAMP = new Date(2019, 5, 1); TIMESTAMP.setUTCHours(0); @@ -37,8 +39,9 @@ describe('reads', async () => { const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); + const instancePath = `projects/${projectId}/instances/${INSTANCE_ID}`; const request = { - parent: adminClient.instancePath(projectId, INSTANCE_ID), + parent: instancePath, tableId: TABLE_ID, table: { columnFamilies: { @@ -47,7 +50,8 @@ describe('reads', async () => { }, }; await adminClient.createTable(request); - table = instance.table(TABLE_ID); + const handwrittenInstance = bigtable.instance(INSTANCE_ID); + table = handwrittenInstance.table(TABLE_ID); const rowsToInsert = [ { diff --git a/samples/test/write.js b/samples/test/write.js index 16e85a4be..bac776a8c 100644 --- a/samples/test/write.js +++ b/samples/test/write.js @@ -27,20 +27,22 @@ describe('writes', async () => { let INSTANCE_ID; before(async () => { - const instance = await obtainTestInstance(); - INSTANCE_ID = instance.id; + const [instance] = await obtainTestInstance(); + INSTANCE_ID = instance.displayName; const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); + const instancePath = `projects/${projectId}/instances/${INSTANCE_ID}`; + const tablePath = `${instancePath}/tables/${TABLE_ID}`; const request = { - parent: adminClient.instancePath(projectId, INSTANCE_ID), + parent: instancePath, tableId: TABLE_ID, table: {}, }; await adminClient.createTable(request).catch(console.error); const modifyFamiliesReq = { - name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + name: tablePath, modifications: [ { id: 'stats_summary', @@ -48,7 +50,9 @@ describe('writes', async () => { }, ], }; - await adminClient.modifyColumnFamilies(modifyFamiliesReq).catch(console.error); + await adminClient + .modifyColumnFamilies(modifyFamiliesReq) + .catch(console.error); }); it('should do a simple write', async () => { From 88af005b20934670858e794aacad8fa2af6e0042 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 4 Sep 2025 16:29:10 -0400 Subject: [PATCH 67/96] Use the instance admin client in instance.js --- samples/test/instance.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/test/instance.js b/samples/test/instance.js index 30f06d30d..9358e8131 100644 --- a/samples/test/instance.js +++ b/samples/test/instance.js @@ -29,11 +29,11 @@ const instanceSnippets = require('./instance.js'); describe.skip('Instance Snippets', () => { after(async () => { try { - const instance = await bigtable.instance(INSTANCE_ID); - const [exists] = await instance.exists(); - if (exists) { - instance.delete(); - } + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + const instancePath = instanceAdminClient.instancePath(projectId, INSTANCE_ID); + await instanceAdminClient.deleteInstance({name: instancePath}); } catch (err) { // Handle the error. } From 071093ccc50e2894aa94bf9d24d1a9cca30afaf4 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 4 Sep 2025 16:38:42 -0400 Subject: [PATCH 68/96] changes to instances.test.js file --- samples/test/instances.test.js | 35 +++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/samples/test/instances.test.js b/samples/test/instances.test.js index edef50a1c..b4d42ab55 100644 --- a/samples/test/instances.test.js +++ b/samples/test/instances.test.js @@ -29,19 +29,36 @@ const instance = bigtable.instance(instanceId); describe('instances', () => { before(async () => { - const [, operation] = await instance.create({ - clusters: [ - { - id: clusterId, - location: 'us-central1-c', - nodes: 3, + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + const request = { + parent: instanceAdminClient.projectPath(projectId), + instanceId: instanceId, + instance: { + displayName: instanceId, + labels: {}, + type: 'PRODUCTION', + }, + clusters: { + [clusterId]: { + location: instanceAdminClient.locationPath(projectId, 'us-central1-c'), + serveNodes: 3, + defaultStorageType: 'SSD', }, - ], - }); + }, + }; + const [, operation] = await instanceAdminClient.createInstance(request); await operation.promise(); }); - after(() => instance.delete()); + after(async () => { + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + const instancePath = instanceAdminClient.instancePath(projectId, instanceId); + await instanceAdminClient.deleteInstance({name: instancePath}); + }); it('should list zones', () => { const output = exec( From 0b23ff42d24f3a3197a96288a97f399dcecb913b Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Tue, 9 Sep 2025 11:55:22 -0400 Subject: [PATCH 69/96] Get rid of calls to locationPath --- samples/test/app-profile.js | 5 +---- samples/test/cluster.js | 11 +++++------ samples/test/family.js | 2 +- samples/test/instances.test.js | 2 +- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/samples/test/app-profile.js b/samples/test/app-profile.js index 2c7b3f7aa..b0c1f6a21 100644 --- a/samples/test/app-profile.js +++ b/samples/test/app-profile.js @@ -38,10 +38,7 @@ describe.skip('App Profile Snippets', () => { }, clusters: { [CLUSTER_ID]: { - location: instanceAdminClient.locationPath( - projectId, - 'us-central1-f', - ), + location: `projects/${projectId}/locations/us-central1-f`, serveNodes: 1, defaultStorageType: 'HDD', }, diff --git a/samples/test/cluster.js b/samples/test/cluster.js index cde297c67..495a6bd78 100644 --- a/samples/test/cluster.js +++ b/samples/test/cluster.js @@ -16,16 +16,12 @@ const uuid = require('uuid'); const {describe, it, before, after} = require('mocha'); -const {Bigtable} = require('@google-cloud/bigtable'); -const bigtable = new Bigtable(); const INSTANCE_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules const CLUSTER_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules const clusterSnippets = require('./cluster.js'); -const instance = bigtable.instance(INSTANCE_ID); - describe.skip('Cluster Snippets', () => { before(async () => { const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; @@ -41,7 +37,7 @@ describe.skip('Cluster Snippets', () => { }, clusters: { [CLUSTER_ID]: { - location: instanceAdminClient.locationPath(projectId, 'us-central1-f'), + location: `projects/${projectId}/locations/us-central1-f`, serveNodes: 1, defaultStorageType: 'HDD', }, @@ -55,7 +51,10 @@ describe.skip('Cluster Snippets', () => { const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; const instanceAdminClient = new BigtableInstanceAdminClient(); const projectId = await instanceAdminClient.getProjectId(); - const instancePath = instanceAdminClient.instancePath(projectId, INSTANCE_ID); + const instancePath = instanceAdminClient.instancePath( + projectId, + INSTANCE_ID, + ); try { await instanceAdminClient.deleteInstance({name: instancePath}); } catch (err) { diff --git a/samples/test/family.js b/samples/test/family.js index f44418b6f..608365ab3 100644 --- a/samples/test/family.js +++ b/samples/test/family.js @@ -44,7 +44,7 @@ describe.skip('Family Snippets', () => { }, clusters: { [CLUSTER_ID]: { - location: instanceAdminClient.locationPath(projectId, 'us-central1-f'), + location: `projects/${projectId}/locations/us-central1-f`, serveNodes: 1, defaultStorageType: 'HDD', }, diff --git a/samples/test/instances.test.js b/samples/test/instances.test.js index b4d42ab55..b13c04222 100644 --- a/samples/test/instances.test.js +++ b/samples/test/instances.test.js @@ -42,7 +42,7 @@ describe('instances', () => { }, clusters: { [clusterId]: { - location: instanceAdminClient.locationPath(projectId, 'us-central1-c'), + location: `projects/${projectId}/locations/us-central1-c`, serveNodes: 3, defaultStorageType: 'SSD', }, From 03cfd0e21f2272836553efe332da533950f9e97d Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Tue, 9 Sep 2025 13:01:38 -0400 Subject: [PATCH 70/96] define instancePath directly --- samples/test/instances.test.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/samples/test/instances.test.js b/samples/test/instances.test.js index b13c04222..5ccfea1de 100644 --- a/samples/test/instances.test.js +++ b/samples/test/instances.test.js @@ -18,14 +18,11 @@ const {assert} = require('chai'); const {describe, it, before, after} = require('mocha'); const uuid = require('uuid'); const {execSync} = require('child_process'); -const {Bigtable} = require('@google-cloud/bigtable'); const exec = cmd => execSync(cmd, {encoding: 'utf8'}); -const bigtable = new Bigtable(); const clusterId = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules const instanceId = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules -const instance = bigtable.instance(instanceId); describe('instances', () => { before(async () => { @@ -56,7 +53,7 @@ describe('instances', () => { const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; const instanceAdminClient = new BigtableInstanceAdminClient(); const projectId = await instanceAdminClient.getProjectId(); - const instancePath = instanceAdminClient.instancePath(projectId, instanceId); + const instancePath = `projects/${projectId}/instances/${instanceId}`; await instanceAdminClient.deleteInstance({name: instancePath}); }); From 5ffd84e498a353fee84eb16063555e17c0cccf78 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Tue, 9 Sep 2025 13:07:15 -0400 Subject: [PATCH 71/96] instancePath should be fixed string --- samples/test/instance.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/samples/test/instance.js b/samples/test/instance.js index 9358e8131..a49df862e 100644 --- a/samples/test/instance.js +++ b/samples/test/instance.js @@ -16,8 +16,6 @@ const uuid = require('uuid'); const {describe, it, after} = require('mocha'); -const {Bigtable} = require('@google-cloud/bigtable'); -const bigtable = new Bigtable(); const INSTANCE_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules const CLUSTER_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules @@ -29,10 +27,11 @@ const instanceSnippets = require('./instance.js'); describe.skip('Instance Snippets', () => { after(async () => { try { - const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const {BigtableInstanceAdminClient} = + require('@google-cloud/bigtable').v2; const instanceAdminClient = new BigtableInstanceAdminClient(); const projectId = await instanceAdminClient.getProjectId(); - const instancePath = instanceAdminClient.instancePath(projectId, INSTANCE_ID); + const instancePath = `projects/${projectId}/instances/${INSTANCE_ID}`; await instanceAdminClient.deleteInstance({name: instancePath}); } catch (err) { // Handle the error. From 7b1b824c163f99aa7febd4c73715f9e5c00ff905 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Tue, 9 Sep 2025 13:38:11 -0400 Subject: [PATCH 72/96] operation is actually first argument --- samples/test/instances.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/test/instances.test.js b/samples/test/instances.test.js index 5ccfea1de..4d7cb975c 100644 --- a/samples/test/instances.test.js +++ b/samples/test/instances.test.js @@ -45,7 +45,7 @@ describe('instances', () => { }, }, }; - const [, operation] = await instanceAdminClient.createInstance(request); + const [operation] = await instanceAdminClient.createInstance(request); await operation.promise(); }); From f8acb599488dfb99c7b595b89deb8139c20daf29 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 4 Sep 2025 16:43:36 -0400 Subject: [PATCH 73/96] Use instance admin client in row.js --- samples/test/row.js | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/samples/test/row.js b/samples/test/row.js index 96e954fb3..049a5a850 100644 --- a/samples/test/row.js +++ b/samples/test/row.js @@ -30,26 +30,35 @@ const instance = bigtable.instance(INSTANCE_ID); describe.skip('Row Snippets', () => { before(async () => { try { - const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; - const [, operation] = await instance.create({ - clusters: [ - { - name: CLUSTER_ID, - location: 'us-central1-f', - storage: 'hdd', + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + const instanceRequest = { + parent: instanceAdminClient.projectPath(projectId), + instanceId: INSTANCE_ID, + instance: { + displayName: INSTANCE_ID, + labels: {}, + type: 'DEVELOPMENT', + }, + clusters: { + [CLUSTER_ID]: { + location: instanceAdminClient.locationPath(projectId, 'us-central1-f'), + serveNodes: 1, + defaultStorageType: 'HDD', }, - ], - type: 'DEVELOPMENT', - }); + }, + }; + const [, operation] = await instanceAdminClient.createInstance(instanceRequest); await operation.promise(); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); - const projectId = await adminClient.getProjectId(); - const request = { + const tableRequest = { parent: adminClient.instancePath(projectId, INSTANCE_ID), tableId: TABLE_ID, table: {}, }; - await adminClient.createTable(request); + await adminClient.createTable(tableRequest); } catch (err) { // Handle the error. } @@ -57,7 +66,11 @@ describe.skip('Row Snippets', () => { after(async () => { try { - await instance.delete(); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + const instancePath = instanceAdminClient.instancePath(projectId, INSTANCE_ID); + await instanceAdminClient.deleteInstance({name: instancePath}); } catch (err) { /// Handle the error. } From 48b97b0619131617e8fadc97c84c942bd34022bb Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 4 Sep 2025 16:49:26 -0400 Subject: [PATCH 74/96] Run linter and fix table.js # Conflicts: # samples/test/cluster.js # samples/test/family.js # samples/test/instance.js # samples/test/instances.test.js --- samples/test/family.js | 11 +++++++--- samples/test/row.js | 19 +++++++++++----- samples/test/table.js | 50 ++++++++++++++++++++++++++++++------------ 3 files changed, 58 insertions(+), 22 deletions(-) diff --git a/samples/test/family.js b/samples/test/family.js index 608365ab3..f8ac925d7 100644 --- a/samples/test/family.js +++ b/samples/test/family.js @@ -31,7 +31,8 @@ const instance = bigtable.instance(INSTANCE_ID); describe.skip('Family Snippets', () => { before(async () => { try { - const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const {BigtableInstanceAdminClient} = + require('@google-cloud/bigtable').v2; const instanceAdminClient = new BigtableInstanceAdminClient(); const projectId = await instanceAdminClient.getProjectId(); const request = { @@ -71,10 +72,14 @@ describe.skip('Family Snippets', () => { after(async () => { try { - const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const {BigtableInstanceAdminClient} = + require('@google-cloud/bigtable').v2; const instanceAdminClient = new BigtableInstanceAdminClient(); const projectId = await instanceAdminClient.getProjectId(); - const instancePath = instanceAdminClient.instancePath(projectId, INSTANCE_ID); + const instancePath = instanceAdminClient.instancePath( + projectId, + INSTANCE_ID, + ); await instanceAdminClient.deleteInstance({name: instancePath}); } catch (err) { // Handle the error. diff --git a/samples/test/row.js b/samples/test/row.js index 049a5a850..792b6ff73 100644 --- a/samples/test/row.js +++ b/samples/test/row.js @@ -30,7 +30,8 @@ const instance = bigtable.instance(INSTANCE_ID); describe.skip('Row Snippets', () => { before(async () => { try { - const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const {BigtableInstanceAdminClient} = + require('@google-cloud/bigtable').v2; const instanceAdminClient = new BigtableInstanceAdminClient(); const projectId = await instanceAdminClient.getProjectId(); const instanceRequest = { @@ -43,13 +44,17 @@ describe.skip('Row Snippets', () => { }, clusters: { [CLUSTER_ID]: { - location: instanceAdminClient.locationPath(projectId, 'us-central1-f'), + location: instanceAdminClient.locationPath( + projectId, + 'us-central1-f', + ), serveNodes: 1, defaultStorageType: 'HDD', }, }, }; - const [, operation] = await instanceAdminClient.createInstance(instanceRequest); + const [, operation] = + await instanceAdminClient.createInstance(instanceRequest); await operation.promise(); const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); @@ -66,10 +71,14 @@ describe.skip('Row Snippets', () => { after(async () => { try { - const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const {BigtableInstanceAdminClient} = + require('@google-cloud/bigtable').v2; const instanceAdminClient = new BigtableInstanceAdminClient(); const projectId = await instanceAdminClient.getProjectId(); - const instancePath = instanceAdminClient.instancePath(projectId, INSTANCE_ID); + const instancePath = instanceAdminClient.instancePath( + projectId, + INSTANCE_ID, + ); await instanceAdminClient.deleteInstance({name: instancePath}); } catch (err) { /// Handle the error. diff --git a/samples/test/table.js b/samples/test/table.js index 414230a11..c2dd31570 100644 --- a/samples/test/table.js +++ b/samples/test/table.js @@ -16,8 +16,6 @@ const uuid = require('uuid'); const {describe, it, before, after} = require('mocha'); -const {Bigtable} = require('@google-cloud/bigtable'); -const bigtable = new Bigtable(); const INSTANCE_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules const CLUSTER_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules @@ -25,21 +23,33 @@ const TABLE_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming r const tableSnippets = require('./table.js'); -const instance = bigtable.instance(INSTANCE_ID); - describe.skip('Table Snippets', () => { before(async () => { try { - const [, operation] = await instance.create({ - clusters: [ - { - name: CLUSTER_ID, - location: 'us-central1-f', - storage: 'hdd', + const {BigtableInstanceAdminClient} = + require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + const request = { + parent: instanceAdminClient.projectPath(projectId), + instanceId: INSTANCE_ID, + instance: { + displayName: INSTANCE_ID, + labels: {}, + type: 'DEVELOPMENT', + }, + clusters: { + [CLUSTER_ID]: { + location: instanceAdminClient.locationPath( + projectId, + 'us-central1-f', + ), + serveNodes: 1, + defaultStorageType: 'HDD', }, - ], - type: 'DEVELOPMENT', - }); + }, + }; + const [, operation] = await instanceAdminClient.createInstance(request); await operation.promise(); } catch (err) { // Handle the error. @@ -47,7 +57,19 @@ describe.skip('Table Snippets', () => { }); after(async () => { - await instance.delete().catch(console.error); + try { + const {BigtableInstanceAdminClient} = + require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + const instancePath = instanceAdminClient.instancePath( + projectId, + INSTANCE_ID, + ); + await instanceAdminClient.deleteInstance({name: instancePath}); + } catch (err) { + // Handle the error. + } }); it('should create a table', () => { From 44ed61c6bc1fb375a1ac154e70f3d4c4c446103b Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 4 Sep 2025 17:01:47 -0400 Subject: [PATCH 75/96] Fix some of the linting errors # Conflicts: # samples/test/util.js --- samples/test/family.js | 4 ---- samples/test/row.js | 4 ---- 2 files changed, 8 deletions(-) diff --git a/samples/test/family.js b/samples/test/family.js index f8ac925d7..7b62c4b24 100644 --- a/samples/test/family.js +++ b/samples/test/family.js @@ -16,8 +16,6 @@ const uuid = require('uuid'); const {describe, it, before, after} = require('mocha'); -const {Bigtable} = require('@google-cloud/bigtable'); -const bigtable = new Bigtable(); const INSTANCE_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules const CLUSTER_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules @@ -26,8 +24,6 @@ const FAMILY_ID = `sample-family-${uuid.v4()}`.substr(0, 10); // Bigtable naming const familySnippets = require('./family.js'); -const instance = bigtable.instance(INSTANCE_ID); - describe.skip('Family Snippets', () => { before(async () => { try { diff --git a/samples/test/row.js b/samples/test/row.js index 792b6ff73..b83a9f475 100644 --- a/samples/test/row.js +++ b/samples/test/row.js @@ -16,8 +16,6 @@ const uuid = require('uuid'); const {describe, it, before, after} = require('mocha'); -const {Bigtable} = require('@google-cloud/bigtable'); -const bigtable = new Bigtable(); const INSTANCE_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules const CLUSTER_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules @@ -25,8 +23,6 @@ const TABLE_ID = `gcloud-tests-${uuid.v4()}`.substr(0, 30); // Bigtable naming r const rowSnippets = require('./row.js'); -const instance = bigtable.instance(INSTANCE_ID); - describe.skip('Row Snippets', () => { before(async () => { try { From ebc9a47573a1a27e08d01e4925b926e410d25779 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 4 Sep 2025 17:40:06 -0400 Subject: [PATCH 76/96] Use instanceAdminClient in instances.js --- samples/instances.js | 155 ++++++++++++++++++++++++++++--------------- 1 file changed, 101 insertions(+), 54 deletions(-) diff --git a/samples/instances.js b/samples/instances.js index 7b8ce48b9..257c96588 100644 --- a/samples/instances.js +++ b/samples/instances.js @@ -18,12 +18,22 @@ const {Bigtable} = require('@google-cloud/bigtable'); async function runInstanceOperations(instanceID, clusterID) { - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceID); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); console.log('Check Instance Exists'); // [START bigtable_check_instance_exists] - const [instanceExists] = await instance.exists(); + let instanceExists = true; + try { + await instanceAdminClient.getInstance({ + name: instanceAdminClient.instancePath(projectId, instanceID), + }); + } catch (e) { + if (e.code === 5) { + instanceExists = false; + } + } // [END bigtable_check_instance_exists] // Create instance if does not exists @@ -34,51 +44,64 @@ async function runInstanceOperations(instanceID, clusterID) { // with cluster id "ssd-cluster", 3 nodes and location us-central1-f const instanceOptions = { - clusters: [ - { - id: clusterID, - nodes: 3, - location: 'us-central1-f', - storage: 'ssd', + parent: instanceAdminClient.projectPath(projectId), + instanceId: instanceID, + instance: { + displayName: instanceID, + labels: {'prod-label': 'prod-label'}, + type: 'PRODUCTION', + }, + clusters: { + [clusterID]: { + location: instanceAdminClient.locationPath( + projectId, + 'us-central1-f', + ), + serveNodes: 3, + defaultStorageType: 'SSD', }, - ], - type: 'PRODUCTION', // Optional as default type is PRODUCTION - labels: {'prod-label': 'prod-label'}, + }, }; // Create production instance with given options - const [prodInstance, operation] = await instance.create(instanceOptions); + const [prodInstance, operation] = + await instanceAdminClient.createInstance(instanceOptions); await operation.promise(); - console.log(`Created Instance: ${prodInstance.id}`); + console.log(`Created Instance: ${prodInstance.name}`); // [END bigtable_create_prod_instance] } else { - console.log(`Instance ${instance.id} exists`); + console.log(`Instance ${instanceID} exists`); } console.log(); //for just a new-line console.log('Listing Instances:'); // [START bigtable_list_instances] - const [instances] = await bigtable.getInstances(); + const [instances] = await instanceAdminClient.listInstances({ + parent: instanceAdminClient.projectPath(projectId), + }); instances.forEach(instance => { - console.log(instance.id); + console.log(instance.name); }); // [END bigtable_list_instances] console.log(); //for just a new-line console.log('Get Instance'); // [START bigtable_get_instance] - const [instances2] = await bigtable.instance(instanceID).get(); - console.log(`Instance ID: ${instances2.id}`); - console.log(`Instance Meta: ${JSON.stringify(instances2.metadata)}`); + const [instance2] = await instanceAdminClient.getInstance({ + name: instanceAdminClient.instancePath(projectId, instanceID), + }); + console.log(`Instance ID: ${instance2.name}`); + console.log(`Instance Meta: ${JSON.stringify(instance2.labels)}`); // [END bigtable_get_instance] console.log(); //for just a new-line console.log('Listing Clusters...'); // [START bigtable_get_clusters] - const instance3 = bigtable.instance(instanceID); - const [clusters] = await instance3.getClusters(); + const [clusters] = await instanceAdminClient.listClusters({ + parent: instanceAdminClient.instancePath(projectId, instanceID), + }); clusters.forEach(cluster => { - console.log(cluster.id); + console.log(cluster.name); }); // [END bigtable_get_clusters] } @@ -87,86 +110,110 @@ async function runInstanceOperations(instanceID, clusterID) { // with cluster ID "hdd-cluster" and location us-central1-f // Cluster nodes should not be set while creating Development Instance async function createDevInstance(instanceID, clusterID) { - const bigtable = new Bigtable(); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); // [START bigtable_create_dev_instance] console.log(); //for just a new-line console.log('Creating a DEVELOPMENT Instance'); // Set options to create an Instance const options = { + parent: instanceAdminClient.projectPath(projectId), + instanceId: instanceID, + instance: { + displayName: instanceID, + labels: {'dev-label': 'dev-label'}, + type: 'DEVELOPMENT', + }, clusters: [ { id: clusterID, - location: 'us-central1-f', - storage: 'hdd', + location: instanceAdminClient.locationPath(projectId, 'us-central1-f'), + serveNodes: 1, + defaultStorageType: 'HDD', }, ], - type: 'DEVELOPMENT', - labels: {'dev-label': 'dev-label'}, }; // Create development instance with given options - const [instance, operation] = await bigtable.createInstance( - instanceID, - options, - ); + const [instance, operation] = + await instanceAdminClient.createInstance(options); await operation.promise(); - console.log(`Created development instance: ${instance.id}`); + console.log(`Created development instance: ${instance.name}`); // [END bigtable_create_dev_instance] } // Delete the Instance async function deleteInstance(instanceID) { // Creates a client - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceID); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); console.log(); //for just a new-line // [START bigtable_delete_instance] console.log('Deleting Instance'); - await instance.delete(); - console.log(`Instance deleted: ${instance.id}`); + await instanceAdminClient.deleteInstance({ + name: instanceAdminClient.instancePath(projectId, instanceID), + }); + console.log(`Instance deleted: ${instanceID}`); // [END bigtable_delete_instance] } // Add Cluster async function addCluster(instanceID, clusterID) { - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceID); - const [instanceExists] = await instance.exists(); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + + let instanceExists = true; + try { + await instanceAdminClient.getInstance({ + name: instanceAdminClient.instancePath(projectId, instanceID), + }); + } catch (e) { + if (e.code === 5) { + instanceExists = false; + } + } if (!instanceExists) { console.log('Instance does not exists'); } else { console.log(); //for just a new-line - console.log(`Adding Cluster to Instance ${instance.id}`); + console.log(`Adding Cluster to Instance ${instanceID}`); // [START bigtable_create_cluster] const clusterOptions = { - location: 'us-central1-c', - nodes: 3, - storage: 'ssd', + parent: instanceAdminClient.instancePath(projectId, instanceID), + clusterId: clusterID, + cluster: { + location: instanceAdminClient.locationPath(projectId, 'us-central1-c'), + serveNodes: 3, + defaultStorageType: 'SSD', + }, }; - const [cluster, operation] = await instance.createCluster( - clusterID, - clusterOptions, - ); + const [cluster, operation] = + await instanceAdminClient.createCluster(clusterOptions); await operation.promise(); - console.log(`Cluster created: ${cluster.id}`); + console.log(`Cluster created: ${cluster.name}`); // [END bigtable_create_cluster] } } // Delete the Cluster async function deleteCluster(instanceID, clusterID) { - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceID); - const cluster = instance.cluster(clusterID); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); // [START bigtable_delete_cluster] console.log(); //for just a new-line console.log('Deleting Cluster'); - await cluster.delete(); - console.log(`Cluster deleted: ${cluster.id}`); + await instanceAdminClient.deleteCluster({ + name: instanceAdminClient.clusterPath(projectId, instanceID, clusterID), + }); + console.log(`Cluster deleted: ${clusterID}`); // [END bigtable_delete_cluster] } From ada69c8deaef52501b1f6105783c95ab40c0b1f4 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 4 Sep 2025 17:45:54 -0400 Subject: [PATCH 77/96] Update the appProfile instance admin samples --- .../api-reference-doc-snippets/app-profile.js | 158 ++++++++++++------ 1 file changed, 104 insertions(+), 54 deletions(-) diff --git a/samples/api-reference-doc-snippets/app-profile.js b/samples/api-reference-doc-snippets/app-profile.js index 44fe89aa7..3839c5ed8 100644 --- a/samples/api-reference-doc-snippets/app-profile.js +++ b/samples/api-reference-doc-snippets/app-profile.js @@ -13,19 +13,29 @@ // limitations under the License. const snippets = { - create: (instanceId, appProfileId) => { + create: async (instanceId, appProfileId) => { // [START bigtable_api_create_app_profile] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const appProfile = instance.appProfile(appProfileId); - // set routing policy, required for creating an app-profile - const options = { - routing: 'any', + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + + const appProfile = { + name: instanceAdminClient.appProfilePath( + projectId, + instanceId, + appProfileId, + ), + multiClusterRoutingUseAny: {}, + }; + + const request = { + parent: instanceAdminClient.instancePath(projectId, instanceId), + appProfileId: appProfileId, + appProfile: appProfile, }; - appProfile - .create(options) + instanceAdminClient + .createAppProfile(request) .then(result => { const appProfile = result[0]; const apiResponse = result[1]; @@ -36,15 +46,22 @@ const snippets = { // [END bigtable_api_create_app_profile] }, - delete: (instanceId, appProfileId) => { + delete: async (instanceId, appProfileId) => { // [START bigtable_api_delete_app_profile] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const appProfile = instance.appProfile(appProfileId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + + const request = { + name: instanceAdminClient.appProfilePath( + projectId, + instanceId, + appProfileId, + ), + }; - appProfile - .delete() + instanceAdminClient + .deleteAppProfile(request) .then(result => { const apiResponse = result[0]; }) @@ -54,33 +71,50 @@ const snippets = { // [END bigtable_api_delete_app_profile] }, - exists: (instanceId, appProfileId) => { + exists: async (instanceId, appProfileId) => { // [START bigtable_api_exists_app_profile] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const appProfile = instance.appProfile(appProfileId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - appProfile - .exists() - .then(result => { - const exists = result[0]; - }) - .catch(err => { + const request = { + name: instanceAdminClient.appProfilePath( + projectId, + instanceId, + appProfileId, + ), + }; + + try { + await instanceAdminClient.getAppProfile(request); + console.log('App profile exists.'); + } catch (err) { + if (err.code === 5) { + console.log('App profile does not exist.'); + } else { // Handle the error. - }); + console.error(err); + } + } // [END bigtable_api_exists_app_profile] }, - get: (instanceId, appProfileId) => { + get: async (instanceId, appProfileId) => { // [START bigtable_api_get_app_profile] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const appProfile = instance.appProfile(appProfileId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + + const request = { + name: instanceAdminClient.appProfilePath( + projectId, + instanceId, + appProfileId, + ), + }; - appProfile - .get() + instanceAdminClient + .getAppProfile(request) .then(result => { const appProfile = result[0]; const apiResponse = result[1]; @@ -91,15 +125,22 @@ const snippets = { // [END bigtable_api_get_app_profile] }, - getMeta: (instanceId, appProfileId) => { + getMeta: async (instanceId, appProfileId) => { // [START bigtable_api_app_profile_get_meta] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const appProfile = instance.appProfile(appProfileId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - appProfile - .getMetadata() + const request = { + name: instanceAdminClient.appProfilePath( + projectId, + instanceId, + appProfileId, + ), + }; + + instanceAdminClient + .getAppProfile(request) .then(result => { const metadata = result[0]; const apiResponse = result[1]; @@ -110,22 +151,31 @@ const snippets = { // [END bigtable_api_app_profile_get_meta] }, - setMeta: (instanceId, appProfileId, clusterId) => { + setMeta: async (instanceId, appProfileId, clusterId) => { // [START bigtable_api_app_profile_set_meta] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const cluster = instance.cluster(clusterId); - const appProfile = instance.appProfile(appProfileId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - const metadata = { + const appProfile = { + name: instanceAdminClient.appProfilePath( + projectId, + instanceId, + appProfileId, + ), description: 'My Updated App Profile', - routing: cluster, - allowTransactionalWrites: true, + multiClusterRoutingUseAny: {}, + }; + + const request = { + appProfile: appProfile, + updateMask: { + paths: ['description', 'multi_cluster_routing_use_any'], + }, }; - appProfile - .setMetadata(metadata) + instanceAdminClient + .updateAppProfile(request) .then(result => { const apiResponse = result[0]; }) From c71b50c52c8df56cae913d9fb379258a03c52530 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Tue, 9 Sep 2025 14:14:38 -0400 Subject: [PATCH 78/96] Revert "Update the appProfile instance admin samples" This reverts commit ada69c8deaef52501b1f6105783c95ab40c0b1f4. --- .../api-reference-doc-snippets/app-profile.js | 158 ++++++------------ 1 file changed, 54 insertions(+), 104 deletions(-) diff --git a/samples/api-reference-doc-snippets/app-profile.js b/samples/api-reference-doc-snippets/app-profile.js index 3839c5ed8..44fe89aa7 100644 --- a/samples/api-reference-doc-snippets/app-profile.js +++ b/samples/api-reference-doc-snippets/app-profile.js @@ -13,29 +13,19 @@ // limitations under the License. const snippets = { - create: async (instanceId, appProfileId) => { + create: (instanceId, appProfileId) => { // [START bigtable_api_create_app_profile] - const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; - const instanceAdminClient = new BigtableInstanceAdminClient(); - const projectId = await instanceAdminClient.getProjectId(); - - const appProfile = { - name: instanceAdminClient.appProfilePath( - projectId, - instanceId, - appProfileId, - ), - multiClusterRoutingUseAny: {}, - }; - - const request = { - parent: instanceAdminClient.instancePath(projectId, instanceId), - appProfileId: appProfileId, - appProfile: appProfile, + const {Bigtable} = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceId); + const appProfile = instance.appProfile(appProfileId); + // set routing policy, required for creating an app-profile + const options = { + routing: 'any', }; - instanceAdminClient - .createAppProfile(request) + appProfile + .create(options) .then(result => { const appProfile = result[0]; const apiResponse = result[1]; @@ -46,22 +36,15 @@ const snippets = { // [END bigtable_api_create_app_profile] }, - delete: async (instanceId, appProfileId) => { + delete: (instanceId, appProfileId) => { // [START bigtable_api_delete_app_profile] - const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; - const instanceAdminClient = new BigtableInstanceAdminClient(); - const projectId = await instanceAdminClient.getProjectId(); - - const request = { - name: instanceAdminClient.appProfilePath( - projectId, - instanceId, - appProfileId, - ), - }; + const {Bigtable} = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceId); + const appProfile = instance.appProfile(appProfileId); - instanceAdminClient - .deleteAppProfile(request) + appProfile + .delete() .then(result => { const apiResponse = result[0]; }) @@ -71,50 +54,33 @@ const snippets = { // [END bigtable_api_delete_app_profile] }, - exists: async (instanceId, appProfileId) => { + exists: (instanceId, appProfileId) => { // [START bigtable_api_exists_app_profile] - const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; - const instanceAdminClient = new BigtableInstanceAdminClient(); - const projectId = await instanceAdminClient.getProjectId(); + const {Bigtable} = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceId); + const appProfile = instance.appProfile(appProfileId); - const request = { - name: instanceAdminClient.appProfilePath( - projectId, - instanceId, - appProfileId, - ), - }; - - try { - await instanceAdminClient.getAppProfile(request); - console.log('App profile exists.'); - } catch (err) { - if (err.code === 5) { - console.log('App profile does not exist.'); - } else { + appProfile + .exists() + .then(result => { + const exists = result[0]; + }) + .catch(err => { // Handle the error. - console.error(err); - } - } + }); // [END bigtable_api_exists_app_profile] }, - get: async (instanceId, appProfileId) => { + get: (instanceId, appProfileId) => { // [START bigtable_api_get_app_profile] - const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; - const instanceAdminClient = new BigtableInstanceAdminClient(); - const projectId = await instanceAdminClient.getProjectId(); - - const request = { - name: instanceAdminClient.appProfilePath( - projectId, - instanceId, - appProfileId, - ), - }; + const {Bigtable} = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceId); + const appProfile = instance.appProfile(appProfileId); - instanceAdminClient - .getAppProfile(request) + appProfile + .get() .then(result => { const appProfile = result[0]; const apiResponse = result[1]; @@ -125,22 +91,15 @@ const snippets = { // [END bigtable_api_get_app_profile] }, - getMeta: async (instanceId, appProfileId) => { + getMeta: (instanceId, appProfileId) => { // [START bigtable_api_app_profile_get_meta] - const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; - const instanceAdminClient = new BigtableInstanceAdminClient(); - const projectId = await instanceAdminClient.getProjectId(); + const {Bigtable} = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceId); + const appProfile = instance.appProfile(appProfileId); - const request = { - name: instanceAdminClient.appProfilePath( - projectId, - instanceId, - appProfileId, - ), - }; - - instanceAdminClient - .getAppProfile(request) + appProfile + .getMetadata() .then(result => { const metadata = result[0]; const apiResponse = result[1]; @@ -151,31 +110,22 @@ const snippets = { // [END bigtable_api_app_profile_get_meta] }, - setMeta: async (instanceId, appProfileId, clusterId) => { + setMeta: (instanceId, appProfileId, clusterId) => { // [START bigtable_api_app_profile_set_meta] - const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; - const instanceAdminClient = new BigtableInstanceAdminClient(); - const projectId = await instanceAdminClient.getProjectId(); + const {Bigtable} = require('@google-cloud/bigtable'); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceId); + const cluster = instance.cluster(clusterId); + const appProfile = instance.appProfile(appProfileId); - const appProfile = { - name: instanceAdminClient.appProfilePath( - projectId, - instanceId, - appProfileId, - ), + const metadata = { description: 'My Updated App Profile', - multiClusterRoutingUseAny: {}, - }; - - const request = { - appProfile: appProfile, - updateMask: { - paths: ['description', 'multi_cluster_routing_use_any'], - }, + routing: cluster, + allowTransactionalWrites: true, }; - instanceAdminClient - .updateAppProfile(request) + appProfile + .setMetadata(metadata) .then(result => { const apiResponse = result[0]; }) From 0ca1f041b6755da09c4313852f66fd81f031ac9f Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Tue, 9 Sep 2025 15:08:38 -0400 Subject: [PATCH 79/96] Must iterate through subobject --- samples/instances.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/instances.js b/samples/instances.js index 257c96588..b72ff0e4f 100644 --- a/samples/instances.js +++ b/samples/instances.js @@ -79,7 +79,7 @@ async function runInstanceOperations(instanceID, clusterID) { const [instances] = await instanceAdminClient.listInstances({ parent: instanceAdminClient.projectPath(projectId), }); - instances.forEach(instance => { + instances.instances.forEach(instance => { console.log(instance.name); }); // [END bigtable_list_instances] @@ -100,7 +100,7 @@ async function runInstanceOperations(instanceID, clusterID) { const [clusters] = await instanceAdminClient.listClusters({ parent: instanceAdminClient.instancePath(projectId, instanceID), }); - clusters.forEach(cluster => { + clusters.clusters.forEach(cluster => { console.log(cluster.name); }); // [END bigtable_get_clusters] From f07432a5ec31a360c46f6a2c303143ac585cf205 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Tue, 9 Sep 2025 15:13:02 -0400 Subject: [PATCH 80/96] Revert "Revert "Update the appProfile instance admin samples"" This reverts commit c71b50c52c8df56cae913d9fb379258a03c52530. --- .../api-reference-doc-snippets/app-profile.js | 158 ++++++++++++------ 1 file changed, 104 insertions(+), 54 deletions(-) diff --git a/samples/api-reference-doc-snippets/app-profile.js b/samples/api-reference-doc-snippets/app-profile.js index 44fe89aa7..3839c5ed8 100644 --- a/samples/api-reference-doc-snippets/app-profile.js +++ b/samples/api-reference-doc-snippets/app-profile.js @@ -13,19 +13,29 @@ // limitations under the License. const snippets = { - create: (instanceId, appProfileId) => { + create: async (instanceId, appProfileId) => { // [START bigtable_api_create_app_profile] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const appProfile = instance.appProfile(appProfileId); - // set routing policy, required for creating an app-profile - const options = { - routing: 'any', + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + + const appProfile = { + name: instanceAdminClient.appProfilePath( + projectId, + instanceId, + appProfileId, + ), + multiClusterRoutingUseAny: {}, + }; + + const request = { + parent: instanceAdminClient.instancePath(projectId, instanceId), + appProfileId: appProfileId, + appProfile: appProfile, }; - appProfile - .create(options) + instanceAdminClient + .createAppProfile(request) .then(result => { const appProfile = result[0]; const apiResponse = result[1]; @@ -36,15 +46,22 @@ const snippets = { // [END bigtable_api_create_app_profile] }, - delete: (instanceId, appProfileId) => { + delete: async (instanceId, appProfileId) => { // [START bigtable_api_delete_app_profile] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const appProfile = instance.appProfile(appProfileId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + + const request = { + name: instanceAdminClient.appProfilePath( + projectId, + instanceId, + appProfileId, + ), + }; - appProfile - .delete() + instanceAdminClient + .deleteAppProfile(request) .then(result => { const apiResponse = result[0]; }) @@ -54,33 +71,50 @@ const snippets = { // [END bigtable_api_delete_app_profile] }, - exists: (instanceId, appProfileId) => { + exists: async (instanceId, appProfileId) => { // [START bigtable_api_exists_app_profile] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const appProfile = instance.appProfile(appProfileId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - appProfile - .exists() - .then(result => { - const exists = result[0]; - }) - .catch(err => { + const request = { + name: instanceAdminClient.appProfilePath( + projectId, + instanceId, + appProfileId, + ), + }; + + try { + await instanceAdminClient.getAppProfile(request); + console.log('App profile exists.'); + } catch (err) { + if (err.code === 5) { + console.log('App profile does not exist.'); + } else { // Handle the error. - }); + console.error(err); + } + } // [END bigtable_api_exists_app_profile] }, - get: (instanceId, appProfileId) => { + get: async (instanceId, appProfileId) => { // [START bigtable_api_get_app_profile] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const appProfile = instance.appProfile(appProfileId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + + const request = { + name: instanceAdminClient.appProfilePath( + projectId, + instanceId, + appProfileId, + ), + }; - appProfile - .get() + instanceAdminClient + .getAppProfile(request) .then(result => { const appProfile = result[0]; const apiResponse = result[1]; @@ -91,15 +125,22 @@ const snippets = { // [END bigtable_api_get_app_profile] }, - getMeta: (instanceId, appProfileId) => { + getMeta: async (instanceId, appProfileId) => { // [START bigtable_api_app_profile_get_meta] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const appProfile = instance.appProfile(appProfileId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - appProfile - .getMetadata() + const request = { + name: instanceAdminClient.appProfilePath( + projectId, + instanceId, + appProfileId, + ), + }; + + instanceAdminClient + .getAppProfile(request) .then(result => { const metadata = result[0]; const apiResponse = result[1]; @@ -110,22 +151,31 @@ const snippets = { // [END bigtable_api_app_profile_get_meta] }, - setMeta: (instanceId, appProfileId, clusterId) => { + setMeta: async (instanceId, appProfileId, clusterId) => { // [START bigtable_api_app_profile_set_meta] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const cluster = instance.cluster(clusterId); - const appProfile = instance.appProfile(appProfileId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - const metadata = { + const appProfile = { + name: instanceAdminClient.appProfilePath( + projectId, + instanceId, + appProfileId, + ), description: 'My Updated App Profile', - routing: cluster, - allowTransactionalWrites: true, + multiClusterRoutingUseAny: {}, + }; + + const request = { + appProfile: appProfile, + updateMask: { + paths: ['description', 'multi_cluster_routing_use_any'], + }, }; - appProfile - .setMetadata(metadata) + instanceAdminClient + .updateAppProfile(request) .then(result => { const apiResponse = result[0]; }) From 497f9a9ebf7745ed90032d7e726fc053f2a599ad Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 4 Sep 2025 17:54:48 -0400 Subject: [PATCH 81/96] Make updates to the cluster.js file --- samples/api-reference-doc-snippets/cluster.js | 129 +++++++++++------- 1 file changed, 80 insertions(+), 49 deletions(-) diff --git a/samples/api-reference-doc-snippets/cluster.js b/samples/api-reference-doc-snippets/cluster.js index 31b1387ee..5e91da2c2 100644 --- a/samples/api-reference-doc-snippets/cluster.js +++ b/samples/api-reference-doc-snippets/cluster.js @@ -13,15 +13,24 @@ // limitations under the License. const snippets = { - create: (instanceId, clusterId) => { + create: async (instanceId, clusterId) => { // [START bigtable_api_create_cluster] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const cluster = instance.cluster(clusterId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - cluster - .create() + const request = { + parent: instanceAdminClient.instancePath(projectId, instanceId), + clusterId: clusterId, + cluster: { + location: instanceAdminClient.locationPath(projectId, 'us-central1-f'), + serveNodes: 1, + defaultStorageType: 'HDD', + }, + }; + + instanceAdminClient + .createCluster(request) .then(result => { const cluster = result[0]; const operation = result[1]; @@ -33,15 +42,18 @@ const snippets = { // [END bigtable_api_create_cluster] }, - delete: (instanceId, clusterId) => { + delete: async (instanceId, clusterId) => { // [START bigtable_api_delete_cluster] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const cluster = instance.cluster(clusterId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + + const request = { + name: instanceAdminClient.clusterPath(projectId, instanceId, clusterId), + }; - cluster - .delete() + instanceAdminClient + .deleteCluster(request) .then(result => { const apiResponse = result[0]; }) @@ -51,33 +63,42 @@ const snippets = { // [END bigtable_api_delete_cluster] }, - exists: (instanceId, clusterId) => { + exists: async (instanceId, clusterId) => { // [START bigtable_api_exists_cluster] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const cluster = instance.cluster(clusterId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - cluster - .exists() - .then(result => { - const exists = result[0]; - }) - .catch(err => { + const request = { + name: instanceAdminClient.clusterPath(projectId, instanceId, clusterId), + }; + + try { + await instanceAdminClient.getCluster(request); + console.log('Cluster exists.'); + } catch (err) { + if (err.code === 5) { + console.log('Cluster does not exist.'); + } else { // Handle the error. - }); + console.error(err); + } + } // [END bigtable_api_exists_cluster] }, - get: (instanceId, clusterId) => { + get: async (instanceId, clusterId) => { // [START bigtable_api_get_cluster] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const cluster = instance.cluster(clusterId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + + const request = { + name: instanceAdminClient.clusterPath(projectId, instanceId, clusterId), + }; - cluster - .get() + instanceAdminClient + .getCluster(request) .then(result => { const cluster = result[0]; const apiResponse = result[1]; @@ -88,15 +109,18 @@ const snippets = { // [END bigtable_api_get_cluster] }, - getMeta: (instanceId, clusterId) => { + getMeta: async (instanceId, clusterId) => { // [START bigtable_api_cluster_get_meta] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const cluster = instance.cluster(clusterId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - cluster - .getMetadata() + const request = { + name: instanceAdminClient.clusterPath(projectId, instanceId, clusterId), + }; + + instanceAdminClient + .getCluster(request) .then(result => { const metadata = result[0]; const apiResponse = result[1]; @@ -107,19 +131,26 @@ const snippets = { // [END bigtable_api_cluster_get_meta] }, - setMeta: (instanceId, clusterId) => { + setMeta: async (instanceId, clusterId) => { // [START bigtable_api_cluster_set_meta] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - const cluster = instance.cluster(clusterId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + + const cluster = { + name: instanceAdminClient.clusterPath(projectId, instanceId, clusterId), + serveNodes: 4, + }; - const metadata = { - nodes: 4, + const request = { + cluster: cluster, + updateMask: { + paths: ['serve_nodes'], + }, }; - cluster - .setMetadata(metadata) + instanceAdminClient + .updateCluster(request) .then(result => { const operation = result[0]; const apiResponse = result[1]; From b9f9cbef8fd72779a0c1b52f5d9a9e14043803dc Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Fri, 5 Sep 2025 09:58:44 -0400 Subject: [PATCH 82/96] instance.js use the instanceAdminClient --- .../api-reference-doc-snippets/instance.js | 143 +++++++++--------- 1 file changed, 73 insertions(+), 70 deletions(-) diff --git a/samples/api-reference-doc-snippets/instance.js b/samples/api-reference-doc-snippets/instance.js index 8ba81e61b..c1c8382a6 100644 --- a/samples/api-reference-doc-snippets/instance.js +++ b/samples/api-reference-doc-snippets/instance.js @@ -13,68 +13,57 @@ // limitations under the License. const snippets = { - createInstance: (instanceId, clusterId) => { + createInstance: async (instanceId, clusterId) => { // [START bigtable_api_create_instance] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - // options for a PRODUCTION Instance - // const options = { - // clusters: [ - // { - // id: clusterId, - // nodes: 3, - // location: 'us-central1-f', - // storage: 'ssd', - // }, - // ], - // type: 'PRODUCTION', // Optional as default type is PRODUCTION - // }; - - // options for a DEVELOPMENT Instance const options = { - clusters: [ - { - id: clusterId, - location: 'us-central1-f', - storage: 'hdd', + parent: instanceAdminClient.projectPath(projectId), + instanceId: instanceId, + instance: { + displayName: instanceId, + labels: {}, + type: 'DEVELOPMENT', + }, + clusters: { + [clusterId]: { + location: instanceAdminClient.locationPath(projectId, 'us-central1-f'), + serveNodes: 1, + defaultStorageType: 'HDD', }, - ], - type: 'DEVELOPMENT', + }, }; // creates a new Instance - instance - .create(options) - .then(result => { - const newInstance = result[0]; - // let operations = result[1]; - // let apiResponse = result[2]; - }) - .catch(err => { - // Handle the error. - }); + const [newInstance, operation] = await instanceAdminClient.createInstance(options); + // let operations = result[1]; + // let apiResponse = result[2]; + }) + .catch(err => { + // Handle the error. + }); // [END bigtable_api_create_instance] }, - createCluster: (instanceId, clusterId) => { + createCluster: async (instanceId, clusterId) => { // [START bigtable_api_create_cluster] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - // const options = { - // location: 'us-central1-b', - // nodes: 3, - // storage: 'ssd', - // }; const options = { - location: 'us-central1-b', - storage: 'hdd', + parent: instanceAdminClient.instancePath(projectId, instanceId), + clusterId: clusterId, + cluster: { + location: instanceAdminClient.locationPath(projectId, 'us-central1-b'), + serveNodes: 1, + defaultStorageType: 'HDD', + }, }; - instance - .createCluster(clusterId, options) + instanceAdminClient + .createCluster(options) .then(result => { const newCluster = result[0]; // const operations = result[1]; @@ -86,21 +75,28 @@ const snippets = { // [END bigtable_api_create_cluster] }, - createAppProfile: (instanceId, clusterId, appProfileId, callback) => { + createAppProfile: async (instanceId, clusterId, appProfileId, callback) => { // [START bigtable_api_create_app_profile] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); - - const cluster = instance.cluster(clusterId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + + const appProfile = { + name: instanceAdminClient.appProfilePath( + projectId, + instanceId, + appProfileId + ), + multiClusterRoutingUseAny: {}, + }; - const options = { - routing: cluster, - allowTransactionalWrites: true, - ignoreWarnings: true, + const request = { + parent: instanceAdminClient.instancePath(projectId, instanceId), + appProfileId: appProfileId, + appProfile: appProfile, }; - instance.createAppProfile(appProfileId, options, (err, appProfile) => { + instanceAdminClient.createAppProfile(request, (err, appProfile) => { if (err) { // Handle the error. return callback(err); @@ -168,20 +164,27 @@ const snippets = { // [END bigtable_api_create_table] }, - existsInstance: instanceId => { + existsInstance: async (instanceId) => { // [START bigtable_api_exists_instance] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - instance - .exists() - .then(result => { - const exists = result[0]; - }) - .catch(err => { + const request = { + name: instanceAdminClient.instancePath(projectId, instanceId), + }; + + try { + await instanceAdminClient.getInstance(request); + console.log('Instance exists.'); + } catch (err) { + if (err.code === 5) { + console.log('Instance does not exist.'); + } else { // Handle the error. - }); + console.error(err); + } + } // [END bigtable_api_exists_instance] }, From 5d2d711168c1eecfc995df0fae9e20870e7dbb66 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 5 Sep 2025 15:03:38 +0000 Subject: [PATCH 83/96] refactor: update instance.js to use generated client --- .../api-reference-doc-snippets/instance.js | 256 ++++++++++-------- 1 file changed, 141 insertions(+), 115 deletions(-) diff --git a/samples/api-reference-doc-snippets/instance.js b/samples/api-reference-doc-snippets/instance.js index c1c8382a6..5f0505d40 100644 --- a/samples/api-reference-doc-snippets/instance.js +++ b/samples/api-reference-doc-snippets/instance.js @@ -188,14 +188,18 @@ const snippets = { // [END bigtable_api_exists_instance] }, - getInstance: instanceId => { + getInstance: async instanceId => { // [START bigtable_api_get_instance] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - instance - .get() + const request = { + name: instanceAdminClient.instancePath(projectId, instanceId), + }; + + instanceAdminClient + .getInstance(request) .then(result => { const instance = result[0]; // const apiResponse = result[1]; @@ -206,14 +210,18 @@ const snippets = { // [END bigtable_api_get_instance] }, - getClusters: instanceId => { + getClusters: async instanceId => { // [START bigtable_api_get_clusters] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - instance - .getClusters() + const request = { + parent: instanceAdminClient.instancePath(projectId, instanceId), + }; + + instanceAdminClient + .listClusters(request) .then(result => { const clusters = result[0]; }) @@ -223,14 +231,18 @@ const snippets = { // [END bigtable_api_get_clusters] }, - getIamPolicy: instanceId => { + getIamPolicy: async instanceId => { // [START bigtable_api_get_instance_Iam_policy] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + + const request = { + resource: instanceAdminClient.instancePath(projectId, instanceId), + }; - instance - .getIamPolicy() + instanceAdminClient + .getIamPolicy(request) .then(result => { const policy = result[0]; }) @@ -240,11 +252,11 @@ const snippets = { // [END bigtable_api_get_instance_Iam_policy] }, - setIamPolicy: instanceId => { + setIamPolicy: async instanceId => { // [START bigtable_api_set_instance_Iam_policy] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); const policy = { bindings: [ @@ -255,8 +267,13 @@ const snippets = { ], }; - instance - .setIamPolicy(policy) + const request = { + resource: instanceAdminClient.instancePath(projectId, instanceId), + policy: policy, + }; + + instanceAdminClient + .setIamPolicy(request) .then(result => { const setPolicy = result[0]; }) @@ -266,15 +283,19 @@ const snippets = { // [END bigtable_api_set_instance_Iam_policy] }, - testIamPermissions: instanceId => { + testIamPermissions: async instanceId => { // [START bigtable_api_test_instance_Iam_permissions] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - const permissions = ['bigtable.tables.get', 'bigtable.tables.readRows']; - instance - .testIamPermissions(permissions) + const request = { + resource: instanceAdminClient.instancePath(projectId, instanceId), + permissions: ['bigtable.tables.get', 'bigtable.tables.readRows'], + }; + + instanceAdminClient + .testIamPermissions(request) .then(result => { const grantedPermissions = result[0]; }) @@ -284,14 +305,18 @@ const snippets = { // [END bigtable_api_test_instance_Iam_permissions] }, - getAppProfiles: instanceId => { + getAppProfiles: async instanceId => { // [START bigtable_api_get_app_profiles] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + + const request = { + parent: instanceAdminClient.instancePath(projectId, instanceId), + }; - instance - .getAppProfiles() + instanceAdminClient + .listAppProfiles(request) .then(result => { const appProfiles = result[0]; }) @@ -301,14 +326,18 @@ const snippets = { // [END bigtable_api_get_app_profiles] }, - getMetadata: instanceId => { + getMetadata: async instanceId => { // [START bigtable_api_get_instance_metadata] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - instance - .getMetadata() + const request = { + name: instanceAdminClient.instancePath(projectId, instanceId), + }; + + instanceAdminClient + .getInstance(request) .then(result => { const metaData = result[0]; }) @@ -318,23 +347,24 @@ const snippets = { // [END bigtable_api_get_instance_metadata] }, - getTables: instanceId => { + getTables: async instanceId => { // [START bigtable_api_get_tables] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const tableAdminClient = new BigtableTableAdminClient(); + const projectId = await tableAdminClient.getProjectId(); // To control how many API requests are made and page through the results // manually, set `autoPaginate` to false. const options = { + parent: tableAdminClient.instancePath(projectId, instanceId), autoPaginate: false, }; // const options = { // autoPaginate: true // }; - instance - .getTables(options) + tableAdminClient + .listTables(options) .then(result => { const tables = result[0]; }) @@ -344,18 +374,24 @@ const snippets = { // [END bigtable_api_get_tables] }, - updateInstance: instanceId => { + updateInstance: async instanceId => { // [START bigtable_api_set_meta_data] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - const metadata = { - displayName: 'updated-name', + const request = { + instance: { + name: instanceAdminClient.instancePath(projectId, instanceId), + displayName: 'updated-name', + }, + updateMask: { + paths: ['display_name'], + }, }; - instance - .setMetadata(metadata) + instanceAdminClient + .partialUpdateInstance(request) .then(result => { const apiResponse = result[0]; }) @@ -365,14 +401,18 @@ const snippets = { // [END bigtable_api_set_meta_data] }, - delInstance: instanceId => { + delInstance: async instanceId => { // [START bigtable_api_del_instance] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); - instance - .delete() + const request = { + name: instanceAdminClient.instancePath(projectId, instanceId), + }; + + instanceAdminClient + .deleteInstance(request) .then(result => { const apiResponse = result[0]; }) @@ -382,36 +422,29 @@ const snippets = { // [END bigtable_api_del_instance] }, - executeQuery: (instanceId, tableId) => { + executeQuery: async (instanceId, tableId) => { // [START bigtable_api_execute_query] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); + const {Bigtable} = require('@google-cloud/bigtable').v2; + const bigtableClient = new Bigtable(); + const projectId = await bigtableClient.getProjectId(); const query = `SELECT _key from \`${tableId}\` WHERE _key=@row_key`; - const parameters = { - row_key: 'alincoln', - }; - - const parameterTypes = { - row_key: Bigtable.SqlTypes.String(), - }; - - const prepareStatementOptions = { + const request = { + instanceName: bigtableClient.instancePath(projectId, instanceId), query, - parameterTypes, + params: { + fields: { + row_key: { + stringValue: 'alincoln', + }, + }, + }, }; - instance - .prepareStatement(prepareStatementOptions) - .then(([preparedStatement]) => - instance.executeQuery({ - preparedStatement, - parameters, - }), - ) + bigtableClient + .executeQuery(request) .then(result => { const rows = result[0]; }) @@ -422,43 +455,36 @@ const snippets = { // [END bigtable_api_execute_query] }, - createExecuteQueryStream: (instanceId, tableId) => { + createExecuteQueryStream: async (instanceId, tableId) => { // [START bigtable_api_create_query_stream] - const {Bigtable} = require('@google-cloud/bigtable'); - const bigtable = new Bigtable(); - const instance = bigtable.instance(instanceId); + const {Bigtable} = require('@google-cloud/bigtable').v2; + const bigtableClient = new Bigtable(); + const projectId = await bigtableClient.getProjectId(); const query = `SELECT _key from \`${tableId}\` WHERE _key=@row_key`; - const parameters = { - row_key: 'alincoln', - }; - const parameterTypes = { - row_key: Bigtable.ExecuteQueryTypes.String(), - }; - - const prepareStatementOptions = { + const request = { + instanceName: bigtableClient.instancePath(projectId, instanceId), query, - parameterTypes, + params: { + fields: { + row_key: { + stringValue: 'alincoln', + }, + }, + }, }; - instance - .prepareStatement(prepareStatementOptions) - .then(preparedStatement => { - instance - .createExecuteQueryStream({ - preparedStatement, - parameters, - }) - .on('error', err => { - // Handle the error. - }) - .on('data', row => { - // `row` is a QueryResultRow object. - }) - .on('end', () => { - // All rows retrieved. - }); + bigtableClient + .executeQueryStream(request) + .on('error', err => { + // Handle the error. + }) + .on('data', row => { + // `row` is a QueryResultRow object. + }) + .on('end', () => { + // All rows retrieved. }); // If you anticipate many results, you can end a stream early to prevent From ee69971600f14e498623bbd675726b88eb4aa5d8 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Tue, 9 Sep 2025 16:14:09 -0400 Subject: [PATCH 84/96] replace project path --- samples/api-reference-doc-snippets/backups.create.js | 2 +- samples/api-reference-doc-snippets/instance.js | 2 +- samples/instances.js | 6 +++--- samples/test/app-profile.js | 2 +- samples/test/cluster.js | 2 +- samples/test/family.js | 2 +- samples/test/instances.test.js | 2 +- samples/test/row.js | 2 +- samples/test/table.js | 2 +- samples/test/util.js | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/samples/api-reference-doc-snippets/backups.create.js b/samples/api-reference-doc-snippets/backups.create.js index 85173125a..1a6c8bf28 100644 --- a/samples/api-reference-doc-snippets/backups.create.js +++ b/samples/api-reference-doc-snippets/backups.create.js @@ -36,7 +36,7 @@ async function main( parent: tableAdminClient.clusterPath(projectId, instanceId, clusterId), backupId: backupId, backup: { - sourceTable: tableAdminClient.tablePath(projectId, instanceId, tableId), + sourceTable: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, expireTime: new Date(Date.now() + 7 * 60 * 60 * 1000), // 7 hours from now }, }; diff --git a/samples/api-reference-doc-snippets/instance.js b/samples/api-reference-doc-snippets/instance.js index 5f0505d40..633504a97 100644 --- a/samples/api-reference-doc-snippets/instance.js +++ b/samples/api-reference-doc-snippets/instance.js @@ -20,7 +20,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const options = { - parent: instanceAdminClient.projectPath(projectId), + parent: `projects/${projectId}`, instanceId: instanceId, instance: { displayName: instanceId, diff --git a/samples/instances.js b/samples/instances.js index b72ff0e4f..50690dba5 100644 --- a/samples/instances.js +++ b/samples/instances.js @@ -44,7 +44,7 @@ async function runInstanceOperations(instanceID, clusterID) { // with cluster id "ssd-cluster", 3 nodes and location us-central1-f const instanceOptions = { - parent: instanceAdminClient.projectPath(projectId), + parent: `projects/${projectId}`, instanceId: instanceID, instance: { displayName: instanceID, @@ -77,7 +77,7 @@ async function runInstanceOperations(instanceID, clusterID) { console.log('Listing Instances:'); // [START bigtable_list_instances] const [instances] = await instanceAdminClient.listInstances({ - parent: instanceAdminClient.projectPath(projectId), + parent: `projects/${projectId}`, }); instances.instances.forEach(instance => { console.log(instance.name); @@ -119,7 +119,7 @@ async function createDevInstance(instanceID, clusterID) { console.log('Creating a DEVELOPMENT Instance'); // Set options to create an Instance const options = { - parent: instanceAdminClient.projectPath(projectId), + parent: `projects/${projectId}`, instanceId: instanceID, instance: { displayName: instanceID, diff --git a/samples/test/app-profile.js b/samples/test/app-profile.js index b0c1f6a21..8589bdd2a 100644 --- a/samples/test/app-profile.js +++ b/samples/test/app-profile.js @@ -29,7 +29,7 @@ describe.skip('App Profile Snippets', () => { const instanceAdminClient = new BigtableInstanceAdminClient(); const projectId = await instanceAdminClient.getProjectId(); const request = { - parent: instanceAdminClient.projectPath(projectId), + parent: `projects/${projectId}`, instanceId: INSTANCE_ID, instance: { displayName: INSTANCE_ID, diff --git a/samples/test/cluster.js b/samples/test/cluster.js index 495a6bd78..ad396074a 100644 --- a/samples/test/cluster.js +++ b/samples/test/cluster.js @@ -28,7 +28,7 @@ describe.skip('Cluster Snippets', () => { const instanceAdminClient = new BigtableInstanceAdminClient(); const projectId = await instanceAdminClient.getProjectId(); const request = { - parent: instanceAdminClient.projectPath(projectId), + parent: `projects/${projectId}`, instanceId: INSTANCE_ID, instance: { displayName: INSTANCE_ID, diff --git a/samples/test/family.js b/samples/test/family.js index 7b62c4b24..f29595137 100644 --- a/samples/test/family.js +++ b/samples/test/family.js @@ -32,7 +32,7 @@ describe.skip('Family Snippets', () => { const instanceAdminClient = new BigtableInstanceAdminClient(); const projectId = await instanceAdminClient.getProjectId(); const request = { - parent: instanceAdminClient.projectPath(projectId), + parent: `projects/${projectId}`, instanceId: INSTANCE_ID, instance: { displayName: INSTANCE_ID, diff --git a/samples/test/instances.test.js b/samples/test/instances.test.js index 4d7cb975c..c73a5a731 100644 --- a/samples/test/instances.test.js +++ b/samples/test/instances.test.js @@ -30,7 +30,7 @@ describe('instances', () => { const instanceAdminClient = new BigtableInstanceAdminClient(); const projectId = await instanceAdminClient.getProjectId(); const request = { - parent: instanceAdminClient.projectPath(projectId), + parent: `projects/${projectId}`, instanceId: instanceId, instance: { displayName: instanceId, diff --git a/samples/test/row.js b/samples/test/row.js index b83a9f475..a03f939fb 100644 --- a/samples/test/row.js +++ b/samples/test/row.js @@ -31,7 +31,7 @@ describe.skip('Row Snippets', () => { const instanceAdminClient = new BigtableInstanceAdminClient(); const projectId = await instanceAdminClient.getProjectId(); const instanceRequest = { - parent: instanceAdminClient.projectPath(projectId), + parent: `projects/${projectId}`, instanceId: INSTANCE_ID, instance: { displayName: INSTANCE_ID, diff --git a/samples/test/table.js b/samples/test/table.js index c2dd31570..f2380a099 100644 --- a/samples/test/table.js +++ b/samples/test/table.js @@ -31,7 +31,7 @@ describe.skip('Table Snippets', () => { const instanceAdminClient = new BigtableInstanceAdminClient(); const projectId = await instanceAdminClient.getProjectId(); const request = { - parent: instanceAdminClient.projectPath(projectId), + parent: `projects/${projectId}`, instanceId: INSTANCE_ID, instance: { displayName: INSTANCE_ID, diff --git a/samples/test/util.js b/samples/test/util.js index 8b74395b7..caeadacfc 100644 --- a/samples/test/util.js +++ b/samples/test/util.js @@ -66,7 +66,7 @@ async function createTestInstance() { const projectId = await instanceAdminClient.getProjectId(); const location = 'us-central1-c'; const request = { - parent: instanceAdminClient.projectPath(projectId), + parent: `projects/${projectId}`, instanceId: instanceId, instance: { displayName: instanceId, From 15211f4852c500cb7efb4fc43e5e6d07dc2e489a Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Tue, 9 Sep 2025 16:18:12 -0400 Subject: [PATCH 85/96] Update the location paths --- samples/api-reference-doc-snippets/cluster.js | 2 +- samples/api-reference-doc-snippets/instance.js | 4 ++-- samples/instances.js | 9 +++------ samples/test/row.js | 5 +---- samples/test/table.js | 5 +---- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/samples/api-reference-doc-snippets/cluster.js b/samples/api-reference-doc-snippets/cluster.js index 5e91da2c2..f7fad740f 100644 --- a/samples/api-reference-doc-snippets/cluster.js +++ b/samples/api-reference-doc-snippets/cluster.js @@ -23,7 +23,7 @@ const snippets = { parent: instanceAdminClient.instancePath(projectId, instanceId), clusterId: clusterId, cluster: { - location: instanceAdminClient.locationPath(projectId, 'us-central1-f'), + location: `projects/${projectId}/locations/us-central1-f`, serveNodes: 1, defaultStorageType: 'HDD', }, diff --git a/samples/api-reference-doc-snippets/instance.js b/samples/api-reference-doc-snippets/instance.js index 633504a97..10ceaef83 100644 --- a/samples/api-reference-doc-snippets/instance.js +++ b/samples/api-reference-doc-snippets/instance.js @@ -29,7 +29,7 @@ const snippets = { }, clusters: { [clusterId]: { - location: instanceAdminClient.locationPath(projectId, 'us-central1-f'), + location: `projects/${projectId}/locations/us-central1-f`, serveNodes: 1, defaultStorageType: 'HDD', }, @@ -57,7 +57,7 @@ const snippets = { parent: instanceAdminClient.instancePath(projectId, instanceId), clusterId: clusterId, cluster: { - location: instanceAdminClient.locationPath(projectId, 'us-central1-b'), + location: `projects/${projectId}/locations/us-central1-b`, serveNodes: 1, defaultStorageType: 'HDD', }, diff --git a/samples/instances.js b/samples/instances.js index 50690dba5..31fa3956d 100644 --- a/samples/instances.js +++ b/samples/instances.js @@ -53,10 +53,7 @@ async function runInstanceOperations(instanceID, clusterID) { }, clusters: { [clusterID]: { - location: instanceAdminClient.locationPath( - projectId, - 'us-central1-f', - ), + location: `projects/${projectId}/locations/us-central1-f`, serveNodes: 3, defaultStorageType: 'SSD', }, @@ -129,7 +126,7 @@ async function createDevInstance(instanceID, clusterID) { clusters: [ { id: clusterID, - location: instanceAdminClient.locationPath(projectId, 'us-central1-f'), + location: `projects/${projectId}/locations/us-central1-f`, serveNodes: 1, defaultStorageType: 'HDD', }, @@ -187,7 +184,7 @@ async function addCluster(instanceID, clusterID) { parent: instanceAdminClient.instancePath(projectId, instanceID), clusterId: clusterID, cluster: { - location: instanceAdminClient.locationPath(projectId, 'us-central1-c'), + location: `projects/${projectId}/locations/us-central1-c`, serveNodes: 3, defaultStorageType: 'SSD', }, diff --git a/samples/test/row.js b/samples/test/row.js index a03f939fb..6eee62df0 100644 --- a/samples/test/row.js +++ b/samples/test/row.js @@ -40,10 +40,7 @@ describe.skip('Row Snippets', () => { }, clusters: { [CLUSTER_ID]: { - location: instanceAdminClient.locationPath( - projectId, - 'us-central1-f', - ), + location: `projects/${projectId}/locations/us-central1-f`, serveNodes: 1, defaultStorageType: 'HDD', }, diff --git a/samples/test/table.js b/samples/test/table.js index f2380a099..61bbaefbf 100644 --- a/samples/test/table.js +++ b/samples/test/table.js @@ -40,10 +40,7 @@ describe.skip('Table Snippets', () => { }, clusters: { [CLUSTER_ID]: { - location: instanceAdminClient.locationPath( - projectId, - 'us-central1-f', - ), + location: `projects/${projectId}/locations/us-central1-f`, serveNodes: 1, defaultStorageType: 'HDD', }, From f57f097398d27a29a5dd0ff4255b32b0243eb56b Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Tue, 9 Sep 2025 16:25:50 -0400 Subject: [PATCH 86/96] Fix the backup id paths --- .../api-reference-doc-snippets/backups.delete.js | 7 +------ samples/api-reference-doc-snippets/backups.get.js | 7 +------ .../api-reference-doc-snippets/backups.restore.js | 7 +------ .../api-reference-doc-snippets/backups.update.js | 7 +------ samples/test/backups.js | 14 ++------------ 5 files changed, 6 insertions(+), 36 deletions(-) diff --git a/samples/api-reference-doc-snippets/backups.delete.js b/samples/api-reference-doc-snippets/backups.delete.js index d8962d941..6a2581480 100644 --- a/samples/api-reference-doc-snippets/backups.delete.js +++ b/samples/api-reference-doc-snippets/backups.delete.js @@ -30,12 +30,7 @@ async function main( // const backupId = 'YOUR_BACKUP_ID'; const projectId = await tableAdminClient.getProjectId(); const request = { - name: tableAdminClient.backupPath( - projectId, - instanceId, - clusterId, - backupId, - ), + name: `projects/${projectId}/instances/${instanceId}/clusters/${clusterId}/backups/${backupId}`, }; await tableAdminClient.deleteBackup(request); console.log(`Backup ${backupId} was deleted successfully.`); diff --git a/samples/api-reference-doc-snippets/backups.get.js b/samples/api-reference-doc-snippets/backups.get.js index b349af245..7994dbe47 100644 --- a/samples/api-reference-doc-snippets/backups.get.js +++ b/samples/api-reference-doc-snippets/backups.get.js @@ -31,12 +31,7 @@ async function main( const projectId = await tableAdminClient.getProjectId(); const request = { - name: tableAdminClient.backupPath( - projectId, - instanceId, - clusterId, - backupId, - ), + name: `projects/${projectId}/instances/${instanceId}/clusters/${clusterId}/backups/${backupId}`, }; const [metadata] = await tableAdminClient.getBackup(request); diff --git a/samples/api-reference-doc-snippets/backups.restore.js b/samples/api-reference-doc-snippets/backups.restore.js index 3fab54738..0e7bedc04 100644 --- a/samples/api-reference-doc-snippets/backups.restore.js +++ b/samples/api-reference-doc-snippets/backups.restore.js @@ -37,12 +37,7 @@ async function main( const [operation] = await adminClient.restoreTable({ parent: adminClient.instancePath(projectId, instanceId), tableId, - backup: adminClient.backupPath( - projectId, - instanceId, - clusterId, - backupId, - ), + backup: `projects/${projectId}/instances/${instanceId}/clusters/${clusterId}/backups/${backupId}`, }); // The following call is part of the restoreTable long running operation. diff --git a/samples/api-reference-doc-snippets/backups.update.js b/samples/api-reference-doc-snippets/backups.update.js index 42430d5aa..bc0ee80ad 100644 --- a/samples/api-reference-doc-snippets/backups.update.js +++ b/samples/api-reference-doc-snippets/backups.update.js @@ -32,12 +32,7 @@ async function main( const request = { backup: { - name: tableAdminClient.backupPath( - projectId, - instanceId, - clusterId, - backupId, - ), + name: `projects/${projectId}/instances/${instanceId}/clusters/${clusterId}/backups/${backupId}`, expireTime: new Date(Date.now() + 24 * 60 * 60 * 1000), // 24 hours }, updateMask: { diff --git a/samples/test/backups.js b/samples/test/backups.js index f4f69cbb5..bc92a6b1b 100644 --- a/samples/test/backups.js +++ b/samples/test/backups.js @@ -137,12 +137,7 @@ describe('backups', async () => { const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); const request = { - name: adminClient.backupPath( - projectId, - INSTANCE_ID, - CLUSTER_ID, - BACKUP_ID, - ), + name: `projects/${projectId}/instances/${INSTANCE_ID}/clusters/${CLUSTER_ID}/backups/${BACKUP_ID}`, }; const [metadata] = await adminClient.getBackup(request); @@ -208,12 +203,7 @@ describe('backups', async () => { const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); const [updatedBackup] = await adminClient.getBackup({ - name: adminClient.backupPath( - projectId, - INSTANCE_ID, - CLUSTER_ID, - backupId, - ), + name: `projects/${projectId}/instances/${INSTANCE_ID}/clusters/${CLUSTER_ID}/backups/${backupId}`, }); const newExpireTime = new Date( updatedBackup.expireTime.seconds * 1000, From 9de614841308f57e7d6df3ae9749385dccc97cf8 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 10 Sep 2025 10:03:39 -0400 Subject: [PATCH 87/96] =?UTF-8?q?Don=E2=80=99t=20rely=20on=20admin=20clien?= =?UTF-8?q?t=20for=20path=20building?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samples/api-reference-doc-snippets/backups.create.js | 2 +- samples/api-reference-doc-snippets/backups.list.js | 2 +- samples/api-reference-doc-snippets/cluster.js | 10 +++++----- samples/instances.js | 2 +- samples/test/backups.js | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/samples/api-reference-doc-snippets/backups.create.js b/samples/api-reference-doc-snippets/backups.create.js index 1a6c8bf28..de21133dc 100644 --- a/samples/api-reference-doc-snippets/backups.create.js +++ b/samples/api-reference-doc-snippets/backups.create.js @@ -33,7 +33,7 @@ async function main( const projectId = await tableAdminClient.getProjectId(); const request = { - parent: tableAdminClient.clusterPath(projectId, instanceId, clusterId), + parent: `projects/${projectId}/instances/${instanceId}/clusters/${clusterId}`, backupId: backupId, backup: { sourceTable: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, diff --git a/samples/api-reference-doc-snippets/backups.list.js b/samples/api-reference-doc-snippets/backups.list.js index 919b78215..b9b46876a 100644 --- a/samples/api-reference-doc-snippets/backups.list.js +++ b/samples/api-reference-doc-snippets/backups.list.js @@ -29,7 +29,7 @@ async function main( const projectId = await tableAdminClient.getProjectId(); const request = { - parent: tableAdminClient.clusterPath(projectId, instanceId, clusterId), + parent: `projects/${projectId}/instances/${instanceId}/clusters/${clusterId}`, }; const [backupsFromCluster] = await tableAdminClient.listBackups(request); diff --git a/samples/api-reference-doc-snippets/cluster.js b/samples/api-reference-doc-snippets/cluster.js index f7fad740f..2f25a63ed 100644 --- a/samples/api-reference-doc-snippets/cluster.js +++ b/samples/api-reference-doc-snippets/cluster.js @@ -49,7 +49,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const request = { - name: instanceAdminClient.clusterPath(projectId, instanceId, clusterId), + name: `projects/${projectId}/instances/${instanceId}/clusters/${clusterId}`, }; instanceAdminClient @@ -70,7 +70,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const request = { - name: instanceAdminClient.clusterPath(projectId, instanceId, clusterId), + name: `projects/${projectId}/instances/${instanceId}/clusters/${clusterId}`, }; try { @@ -94,7 +94,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const request = { - name: instanceAdminClient.clusterPath(projectId, instanceId, clusterId), + name: `projects/${projectId}/instances/${instanceId}/clusters/${clusterId}`, }; instanceAdminClient @@ -116,7 +116,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const request = { - name: instanceAdminClient.clusterPath(projectId, instanceId, clusterId), + name: `projects/${projectId}/instances/${instanceId}/clusters/${clusterId}`, }; instanceAdminClient @@ -138,7 +138,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const cluster = { - name: instanceAdminClient.clusterPath(projectId, instanceId, clusterId), + name: `projects/${projectId}/instances/${instanceId}/clusters/${clusterId}`, serveNodes: 4, }; diff --git a/samples/instances.js b/samples/instances.js index 31fa3956d..e43faad20 100644 --- a/samples/instances.js +++ b/samples/instances.js @@ -208,7 +208,7 @@ async function deleteCluster(instanceID, clusterID) { console.log(); //for just a new-line console.log('Deleting Cluster'); await instanceAdminClient.deleteCluster({ - name: instanceAdminClient.clusterPath(projectId, instanceID, clusterID), + name: `projects/${projectId}/instances/${instanceID}/clusters/${clusterID}`, }); console.log(`Cluster deleted: ${clusterID}`); // [END bigtable_delete_cluster] diff --git a/samples/test/backups.js b/samples/test/backups.js index bc92a6b1b..963d0937f 100644 --- a/samples/test/backups.js +++ b/samples/test/backups.js @@ -39,7 +39,7 @@ describe('backups', async () => { const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); const request = { - parent: adminClient.clusterPath(projectId, INSTANCE_ID, CLUSTER_ID), + parent: `projects/${projectId}/instances/${INSTANCE_ID}/clusters/${CLUSTER_ID}`, backupId: backupId, backup: { sourceTable: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), @@ -163,7 +163,7 @@ describe('backups', async () => { parent: adminClient.instancePath(projectId, INSTANCE_ID), }); const [backupsFromCluster] = await adminClient.listBackups({ - parent: adminClient.clusterPath(projectId, INSTANCE_ID, CLUSTER_ID), + parent: `projects/${projectId}/instances/${INSTANCE_ID}/clusters/${CLUSTER_ID}`, }); const stdout = execSync( From a18675114742b28c0609f21f990d35091dbe6584 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 10 Sep 2025 10:16:45 -0400 Subject: [PATCH 88/96] replace all instance paths --- samples/hello-world/index.js | 2 +- samples/test/backups.js | 4 ++-- samples/test/family.js | 2 +- samples/test/functions.js | 2 +- samples/test/row.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/hello-world/index.js b/samples/hello-world/index.js index 52cf15092..e33794edf 100644 --- a/samples/hello-world/index.js +++ b/samples/hello-world/index.js @@ -68,7 +68,7 @@ const getRowGreeting = row => { const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); await adminClient.createTable({ - parent: adminClient.instancePath(projectId, INSTANCE_ID), + parent: `projects/${projectId}/instances/${INSTANCE_ID}`, tableId: TABLE_ID, table: { columnFamilies: { diff --git a/samples/test/backups.js b/samples/test/backups.js index 963d0937f..416c3ff67 100644 --- a/samples/test/backups.js +++ b/samples/test/backups.js @@ -56,7 +56,7 @@ describe('backups', async () => { const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); const request = { - parent: adminClient.instancePath(projectId, INSTANCE_ID), + parent: `projects/${projectId}/instances/${INSTANCE_ID}`, tableId: TABLE_ID, table: {}, }; @@ -160,7 +160,7 @@ describe('backups', async () => { const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); const [backupsFromInstance] = await adminClient.listBackups({ - parent: adminClient.instancePath(projectId, INSTANCE_ID), + parent: `projects/${projectId}/instances/${INSTANCE_ID}`, }); const [backupsFromCluster] = await adminClient.listBackups({ parent: `projects/${projectId}/instances/${INSTANCE_ID}/clusters/${CLUSTER_ID}`, diff --git a/samples/test/family.js b/samples/test/family.js index f29595137..cbf26029f 100644 --- a/samples/test/family.js +++ b/samples/test/family.js @@ -52,7 +52,7 @@ describe.skip('Family Snippets', () => { const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); const tableRequest = { - parent: adminClient.instancePath(projectId, INSTANCE_ID), + parent: `projects/${projectId}/instances/${INSTANCE_ID}`, tableId: TABLE_ID, table: { columnFamilies: { diff --git a/samples/test/functions.js b/samples/test/functions.js index 2f10d5c90..2c90cc275 100644 --- a/samples/test/functions.js +++ b/samples/test/functions.js @@ -44,7 +44,7 @@ describe('functions', async () => { const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); const request = { - parent: adminClient.instancePath(projectId, INSTANCE_ID), + parent: `projects/${projectId}/instances/${INSTANCE_ID}`, tableId: TABLE_ID, table: { columnFamilies: { diff --git a/samples/test/row.js b/samples/test/row.js index 6eee62df0..19ceec2a1 100644 --- a/samples/test/row.js +++ b/samples/test/row.js @@ -52,7 +52,7 @@ describe.skip('Row Snippets', () => { const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); const tableRequest = { - parent: adminClient.instancePath(projectId, INSTANCE_ID), + parent: `projects/${projectId}/instances/${INSTANCE_ID}`, tableId: TABLE_ID, table: {}, }; From 63a678b2b3607423483b10f392bbd805886d7323 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 10 Sep 2025 10:24:01 -0400 Subject: [PATCH 89/96] Use the instance id path --- .../api-reference-doc-snippets/app-profile.js | 2 +- .../backups.restore.js | 2 +- samples/api-reference-doc-snippets/cluster.js | 2 +- .../api-reference-doc-snippets/instance.js | 32 +++++++++---------- samples/api-reference-doc-snippets/table.js | 2 +- samples/instances.js | 12 +++---- samples/tableadmin.js | 2 +- samples/test/backups.js | 2 +- samples/test/util.js | 4 +-- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/samples/api-reference-doc-snippets/app-profile.js b/samples/api-reference-doc-snippets/app-profile.js index 3839c5ed8..4d4919937 100644 --- a/samples/api-reference-doc-snippets/app-profile.js +++ b/samples/api-reference-doc-snippets/app-profile.js @@ -29,7 +29,7 @@ const snippets = { }; const request = { - parent: instanceAdminClient.instancePath(projectId, instanceId), + parent: `projects/${projectId}/instances/${instanceId}`, appProfileId: appProfileId, appProfile: appProfile, }; diff --git a/samples/api-reference-doc-snippets/backups.restore.js b/samples/api-reference-doc-snippets/backups.restore.js index 0e7bedc04..d855e69f7 100644 --- a/samples/api-reference-doc-snippets/backups.restore.js +++ b/samples/api-reference-doc-snippets/backups.restore.js @@ -35,7 +35,7 @@ async function main( // Restore a table to an instance. const [operation] = await adminClient.restoreTable({ - parent: adminClient.instancePath(projectId, instanceId), + parent: `projects/${projectId}/instances/${instanceId}`, tableId, backup: `projects/${projectId}/instances/${instanceId}/clusters/${clusterId}/backups/${backupId}`, }); diff --git a/samples/api-reference-doc-snippets/cluster.js b/samples/api-reference-doc-snippets/cluster.js index 2f25a63ed..fdd298b0c 100644 --- a/samples/api-reference-doc-snippets/cluster.js +++ b/samples/api-reference-doc-snippets/cluster.js @@ -20,7 +20,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const request = { - parent: instanceAdminClient.instancePath(projectId, instanceId), + parent: `projects/${projectId}/instances/${instanceId}`, clusterId: clusterId, cluster: { location: `projects/${projectId}/locations/us-central1-f`, diff --git a/samples/api-reference-doc-snippets/instance.js b/samples/api-reference-doc-snippets/instance.js index 10ceaef83..c2196c007 100644 --- a/samples/api-reference-doc-snippets/instance.js +++ b/samples/api-reference-doc-snippets/instance.js @@ -54,7 +54,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const options = { - parent: instanceAdminClient.instancePath(projectId, instanceId), + parent: `projects/${projectId}/instances/${instanceId}`, clusterId: clusterId, cluster: { location: `projects/${projectId}/locations/us-central1-b`, @@ -91,7 +91,7 @@ const snippets = { }; const request = { - parent: instanceAdminClient.instancePath(projectId, instanceId), + parent: `projects/${projectId}/instances/${instanceId}`, appProfileId: appProfileId, appProfile: appProfile, }; @@ -113,7 +113,7 @@ const snippets = { const projectId = await adminClient.getProjectId(); const request = { - parent: adminClient.instancePath(projectId, instanceId), + parent: `projects/${projectId}/instances/${instanceId}`, tableId: tableId, table: { columnFamilies: { @@ -171,7 +171,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const request = { - name: instanceAdminClient.instancePath(projectId, instanceId), + name: `projects/${projectId}/instances/${instanceId}`, }; try { @@ -195,7 +195,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const request = { - name: instanceAdminClient.instancePath(projectId, instanceId), + name: `projects/${projectId}/instances/${instanceId}`, }; instanceAdminClient @@ -217,7 +217,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const request = { - parent: instanceAdminClient.instancePath(projectId, instanceId), + parent: `projects/${projectId}/instances/${instanceId}`, }; instanceAdminClient @@ -238,7 +238,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const request = { - resource: instanceAdminClient.instancePath(projectId, instanceId), + resource: `projects/${projectId}/instances/${instanceId}`, }; instanceAdminClient @@ -268,7 +268,7 @@ const snippets = { }; const request = { - resource: instanceAdminClient.instancePath(projectId, instanceId), + resource: `projects/${projectId}/instances/${instanceId}`, policy: policy, }; @@ -290,7 +290,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const request = { - resource: instanceAdminClient.instancePath(projectId, instanceId), + resource: `projects/${projectId}/instances/${instanceId}`, permissions: ['bigtable.tables.get', 'bigtable.tables.readRows'], }; @@ -312,7 +312,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const request = { - parent: instanceAdminClient.instancePath(projectId, instanceId), + parent: `projects/${projectId}/instances/${instanceId}`, }; instanceAdminClient @@ -333,7 +333,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const request = { - name: instanceAdminClient.instancePath(projectId, instanceId), + name: `projects/${projectId}/instances/${instanceId}`, }; instanceAdminClient @@ -356,7 +356,7 @@ const snippets = { // To control how many API requests are made and page through the results // manually, set `autoPaginate` to false. const options = { - parent: tableAdminClient.instancePath(projectId, instanceId), + parent: `projects/${projectId}/instances/${instanceId}`, autoPaginate: false, }; // const options = { @@ -382,7 +382,7 @@ const snippets = { const request = { instance: { - name: instanceAdminClient.instancePath(projectId, instanceId), + name: `projects/${projectId}/instances/${instanceId}`, displayName: 'updated-name', }, updateMask: { @@ -408,7 +408,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const request = { - name: instanceAdminClient.instancePath(projectId, instanceId), + name: `projects/${projectId}/instances/${instanceId}`, }; instanceAdminClient @@ -432,7 +432,7 @@ const snippets = { _key from \`${tableId}\` WHERE _key=@row_key`; const request = { - instanceName: bigtableClient.instancePath(projectId, instanceId), + instanceName: `projects/${projectId}/instances/${instanceId}`, query, params: { fields: { @@ -465,7 +465,7 @@ const snippets = { _key from \`${tableId}\` WHERE _key=@row_key`; const request = { - instanceName: bigtableClient.instancePath(projectId, instanceId), + instanceName: `projects/${projectId}/instances/${instanceId}`, query, params: { fields: { diff --git a/samples/api-reference-doc-snippets/table.js b/samples/api-reference-doc-snippets/table.js index 4af9b4906..947a5e5f7 100644 --- a/samples/api-reference-doc-snippets/table.js +++ b/samples/api-reference-doc-snippets/table.js @@ -22,7 +22,7 @@ const snippets = { const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); const request = { - parent: adminClient.instancePath(projectId, instanceId), + parent: `projects/${projectId}/instances/${instanceId}`, tableId: tableId, table: { columnFamilies: { diff --git a/samples/instances.js b/samples/instances.js index e43faad20..9795d5b47 100644 --- a/samples/instances.js +++ b/samples/instances.js @@ -27,7 +27,7 @@ async function runInstanceOperations(instanceID, clusterID) { let instanceExists = true; try { await instanceAdminClient.getInstance({ - name: instanceAdminClient.instancePath(projectId, instanceID), + name: `projects/${projectId}/instances/${instanceID}`, }); } catch (e) { if (e.code === 5) { @@ -85,7 +85,7 @@ async function runInstanceOperations(instanceID, clusterID) { console.log('Get Instance'); // [START bigtable_get_instance] const [instance2] = await instanceAdminClient.getInstance({ - name: instanceAdminClient.instancePath(projectId, instanceID), + name: `projects/${projectId}/instances/${instanceID}`, }); console.log(`Instance ID: ${instance2.name}`); console.log(`Instance Meta: ${JSON.stringify(instance2.labels)}`); @@ -95,7 +95,7 @@ async function runInstanceOperations(instanceID, clusterID) { console.log('Listing Clusters...'); // [START bigtable_get_clusters] const [clusters] = await instanceAdminClient.listClusters({ - parent: instanceAdminClient.instancePath(projectId, instanceID), + parent: `projects/${projectId}/instances/${instanceID}`, }); clusters.clusters.forEach(cluster => { console.log(cluster.name); @@ -152,7 +152,7 @@ async function deleteInstance(instanceID) { // [START bigtable_delete_instance] console.log('Deleting Instance'); await instanceAdminClient.deleteInstance({ - name: instanceAdminClient.instancePath(projectId, instanceID), + name: `projects/${projectId}/instances/${instanceID}`, }); console.log(`Instance deleted: ${instanceID}`); // [END bigtable_delete_instance] @@ -167,7 +167,7 @@ async function addCluster(instanceID, clusterID) { let instanceExists = true; try { await instanceAdminClient.getInstance({ - name: instanceAdminClient.instancePath(projectId, instanceID), + name: `projects/${projectId}/instances/${instanceID}`, }); } catch (e) { if (e.code === 5) { @@ -181,7 +181,7 @@ async function addCluster(instanceID, clusterID) { console.log(`Adding Cluster to Instance ${instanceID}`); // [START bigtable_create_cluster] const clusterOptions = { - parent: instanceAdminClient.instancePath(projectId, instanceID), + parent: `projects/${projectId}/instances/${instanceID}`, clusterId: clusterID, cluster: { location: `projects/${projectId}/locations/us-central1-c`, diff --git a/samples/tableadmin.js b/samples/tableadmin.js index e7f5f6ac9..cddd1ea55 100644 --- a/samples/tableadmin.js +++ b/samples/tableadmin.js @@ -40,7 +40,7 @@ async function runTableOperations(instanceID, tableID) { // Create table if does not exist console.log(`Table does not exist. Creating table ${tableID}`); const request = { - parent: adminClient.instancePath(projectId, instanceID), + parent: `projects/${projectId}/instances/${instanceID}`, tableId: tableID, table: { columnFamilies: { diff --git a/samples/test/backups.js b/samples/test/backups.js index 416c3ff67..ddf46bfc3 100644 --- a/samples/test/backups.js +++ b/samples/test/backups.js @@ -100,7 +100,7 @@ describe('backups', async () => { const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); const [backups] = await adminClient.listBackups({ - parent: `${adminClient.instancePath(projectId, instance.id)}/clusters/-`, + parent: `projects/${projectId}/instances/${instanceId}/clusters/-`, }); return Promise.all( backups.map(backup => { diff --git a/samples/test/util.js b/samples/test/util.js index caeadacfc..ab3177265 100644 --- a/samples/test/util.js +++ b/samples/test/util.js @@ -85,7 +85,7 @@ async function createTestInstance() { const [operation] = await instanceAdminClient.createInstance(request); await operation.promise(); return instanceAdminClient.getInstance({ - name: instanceAdminClient.instancePath(projectId, instanceId), + name: `projects/${projectId}/instances/${instanceId}`, }); } @@ -94,7 +94,7 @@ async function createTestInstance() { */ after(async () => { const projectId = await instanceAdminClient.getProjectId(); - const instancePath = instanceAdminClient.instancePath(projectId, instanceId); + const instancePath = `projects/${projectId}/instances/${instanceId}`; await instanceAdminClient.deleteInstance({name: instancePath}); }); From d501eaf93c61c7007815b229c7d1fde58c4c399b Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 10 Sep 2025 10:32:51 -0400 Subject: [PATCH 90/96] Replace table path builders --- samples/api-reference-doc-snippets/family.js | 12 +++++------ samples/api-reference-doc-snippets/table.js | 22 ++++++++++---------- samples/deleteSnippets.js | 6 +++--- samples/hello-world/index.js | 4 ++-- samples/tableadmin.js | 2 +- samples/test/backups.js | 4 ++-- samples/test/filters.js | 2 +- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/samples/api-reference-doc-snippets/family.js b/samples/api-reference-doc-snippets/family.js index a93950141..fd5e3b270 100644 --- a/samples/api-reference-doc-snippets/family.js +++ b/samples/api-reference-doc-snippets/family.js @@ -21,7 +21,7 @@ const snippets = { const projectId = await adminClient.getProjectId(); const request = { - name: adminClient.tablePath(projectId, instanceId, tableId), + name: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, modifications: [ { id: familyId, @@ -48,7 +48,7 @@ const snippets = { const projectId = await adminClient.getProjectId(); const request = { - name: adminClient.tablePath(projectId, instanceId, tableId), + name: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, view: 'FAMILY_VIEW_BASIC', }; @@ -72,7 +72,7 @@ const snippets = { const projectId = await adminClient.getProjectId(); const request = { - name: adminClient.tablePath(projectId, instanceId, tableId), + name: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, view: 'FULL', }; @@ -95,7 +95,7 @@ const snippets = { const projectId = await adminClient.getProjectId(); const request = { - name: adminClient.tablePath(projectId, instanceId, tableId), + name: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, view: 'FULL', }; @@ -124,7 +124,7 @@ const snippets = { }; const request = { - name: adminClient.tablePath(projectId, instanceId, tableId), + name: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, modifications: [ { id: familyId, @@ -152,7 +152,7 @@ const snippets = { const projectId = await adminClient.getProjectId(); const request = { - name: adminClient.tablePath(projectId, instanceId, tableId), + name: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, modifications: [ { id: familyId, diff --git a/samples/api-reference-doc-snippets/table.js b/samples/api-reference-doc-snippets/table.js index 947a5e5f7..10e70161f 100644 --- a/samples/api-reference-doc-snippets/table.js +++ b/samples/api-reference-doc-snippets/table.js @@ -49,7 +49,7 @@ const snippets = { const projectId = await adminClient.getProjectId(); const request = { - name: adminClient.tablePath(projectId, instanceId, tableId), + name: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, }; try { @@ -73,7 +73,7 @@ const snippets = { const projectId = await adminClient.getProjectId(); const request = { - name: adminClient.tablePath(projectId, instanceId, tableId), + name: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, }; adminClient @@ -95,7 +95,7 @@ const snippets = { const projectId = await adminClient.getProjectId(); const request = { - name: adminClient.tablePath(projectId, instanceId, tableId), + name: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, view: 'FULL', }; @@ -129,7 +129,7 @@ const snippets = { adminClient .modifyColumnFamilies({ - name: adminClient.tablePath(projectId, instanceId, tableId), + name: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, modifications: [ { id: familyId, @@ -156,7 +156,7 @@ const snippets = { const projectId = await adminClient.getProjectId(); const request = { - name: adminClient.tablePath(projectId, instanceId, tableId), + name: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, view: 'FULL', }; @@ -347,7 +347,7 @@ const snippets = { const projectId = await adminClient.getProjectId(); const request = { - resource: adminClient.tablePath(projectId, instanceId, tableId), + resource: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, }; adminClient @@ -377,7 +377,7 @@ const snippets = { }; const request = { - resource: adminClient.tablePath(projectId, instanceId, tableId), + resource: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, policy: policy, }; @@ -401,7 +401,7 @@ const snippets = { const permissions = ['bigtable.tables.get', 'bigtable.tables.readRows']; const request = { - resource: adminClient.tablePath(projectId, instanceId, tableId), + resource: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, permissions: permissions, }; @@ -439,7 +439,7 @@ const snippets = { const projectId = await adminClient.getProjectId(); const request = { - name: adminClient.tablePath(projectId, instanceId, tableId), + name: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, }; adminClient @@ -461,7 +461,7 @@ const snippets = { // 1. Generate a consistency token. const token = ( await adminClient.generateConsistencyToken({ - name: adminClient.tablePath(projectId, instanceId, tableId), + name: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, }) )[0].consistencyToken; console.log('Generated consistency token:', token); @@ -469,7 +469,7 @@ const snippets = { while (!isConsistent) { // 2. Check for consistency const [consistent] = adminClient.checkConsistency({ - name: adminClient.tablePath(projectId, instanceId, tableId), + name: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, consistencyToken: token, }); isConsistent = consistent; diff --git a/samples/deleteSnippets.js b/samples/deleteSnippets.js index 173985718..04c08eb12 100644 --- a/samples/deleteSnippets.js +++ b/samples/deleteSnippets.js @@ -115,7 +115,7 @@ async function main( const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); const request = { - name: adminClient.tablePath(projectId, instanceId, tableId), + name: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, modifications: [ { id: 'stats_summary', @@ -134,13 +134,13 @@ async function main( const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); const request = { - name: adminClient.tablePath(projectId, instanceId, tableId), + name: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, }; await adminClient.deleteTable(request); console.log( await adminClient .getTable({ - name: adminClient.tablePath(projectId, instanceId, tableId), + name: `projects/${projectId}/instances/${instanceId}/tables/${tableId}`, }) .catch(e => (e.code === 5 ? false : e)), ); diff --git a/samples/hello-world/index.js b/samples/hello-world/index.js index e33794edf..698f4ba46 100644 --- a/samples/hello-world/index.js +++ b/samples/hello-world/index.js @@ -55,7 +55,7 @@ const getRowGreeting = row => { let tableExists = true; try { await adminClient.getTable({ - name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + name: `projects/${projectId}/instances/${INSTANCE_ID}/tables/${TABLE_ID}`, }); } catch (e) { if (e.code === 5) { @@ -141,7 +141,7 @@ const getRowGreeting = row => { // [START bigtable_hw_delete_table] console.log('Delete the table'); const request = { - name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + name: `projects/${projectId}/instances/${INSTANCE_ID}/tables/${TABLE_ID}`, }; await adminClient.deleteTable(request); // [END bigtable_hw_delete_table] diff --git a/samples/tableadmin.js b/samples/tableadmin.js index cddd1ea55..7d3d23fc1 100644 --- a/samples/tableadmin.js +++ b/samples/tableadmin.js @@ -315,7 +315,7 @@ async function deleteTable(instanceID, tableID) { // Delete the entire table console.log('Delete the table.'); await adminClient.deleteTable({ - name: adminClient.tablePath(projectId, instanceID, tableID), + name: `projects/${projectId}/instances/${instanceID}/tables/${tableID}`, }); console.log(`Table deleted: ${tableID}`); // [END bigtable_delete_table] diff --git a/samples/test/backups.js b/samples/test/backups.js index ddf46bfc3..8aba1c191 100644 --- a/samples/test/backups.js +++ b/samples/test/backups.js @@ -42,7 +42,7 @@ describe('backups', async () => { parent: `projects/${projectId}/instances/${INSTANCE_ID}/clusters/${CLUSTER_ID}`, backupId: backupId, backup: { - sourceTable: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + sourceTable: `projects/${projectId}/instances/${INSTANCE_ID}/tables/${TABLE_ID}`, expireTime: new Date(Date.now() + 60 * 60 * 1000), // 1 hour from now }, }; @@ -62,7 +62,7 @@ describe('backups', async () => { }; await adminClient.createTable(request); const modifyFamiliesReq = { - name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + name: `projects/${projectId}/instances/${INSTANCE_ID}/tables/${TABLE_ID}`, modifications: [ { id: 'follows', diff --git a/samples/test/filters.js b/samples/test/filters.js index b18eef8be..4538adbc4 100644 --- a/samples/test/filters.js +++ b/samples/test/filters.js @@ -227,7 +227,7 @@ describe('filters', async () => { const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); const request = { - name: adminClient.tablePath(projectId, INSTANCE_ID, TABLE_ID), + name: `projects/${projectId}/instances/${INSTANCE_ID}/tables/${TABLE_ID}`, }; await adminClient.deleteTable(request).catch(console.error); }); From eacbd169369d84a44ee1344fff7813cf9c9a9970 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 10 Sep 2025 11:07:14 -0400 Subject: [PATCH 91/96] Replace appProfileId path --- .../api-reference-doc-snippets/app-profile.js | 36 ++++--------------- .../api-reference-doc-snippets/instance.js | 6 +--- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/samples/api-reference-doc-snippets/app-profile.js b/samples/api-reference-doc-snippets/app-profile.js index 4d4919937..ba129a18b 100644 --- a/samples/api-reference-doc-snippets/app-profile.js +++ b/samples/api-reference-doc-snippets/app-profile.js @@ -20,11 +20,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const appProfile = { - name: instanceAdminClient.appProfilePath( - projectId, - instanceId, - appProfileId, - ), + name: `projects/${projectId}/instances/${instanceId}/appProfiles/${appProfileId}`, multiClusterRoutingUseAny: {}, }; @@ -53,11 +49,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const request = { - name: instanceAdminClient.appProfilePath( - projectId, - instanceId, - appProfileId, - ), + name: `projects/${projectId}/instances/${instanceId}/appProfiles/${appProfileId}`, }; instanceAdminClient @@ -78,11 +70,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const request = { - name: instanceAdminClient.appProfilePath( - projectId, - instanceId, - appProfileId, - ), + name: `projects/${projectId}/instances/${instanceId}/appProfiles/${appProfileId}`, }; try { @@ -106,11 +94,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const request = { - name: instanceAdminClient.appProfilePath( - projectId, - instanceId, - appProfileId, - ), + name: `projects/${projectId}/instances/${instanceId}/appProfiles/${appProfileId}`, }; instanceAdminClient @@ -132,11 +116,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const request = { - name: instanceAdminClient.appProfilePath( - projectId, - instanceId, - appProfileId, - ), + name: `projects/${projectId}/instances/${instanceId}/appProfiles/${appProfileId}`, }; instanceAdminClient @@ -158,11 +138,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const appProfile = { - name: instanceAdminClient.appProfilePath( - projectId, - instanceId, - appProfileId, - ), + name: `projects/${projectId}/instances/${instanceId}/appProfiles/${appProfileId}`, description: 'My Updated App Profile', multiClusterRoutingUseAny: {}, }; diff --git a/samples/api-reference-doc-snippets/instance.js b/samples/api-reference-doc-snippets/instance.js index c2196c007..73a21fb2d 100644 --- a/samples/api-reference-doc-snippets/instance.js +++ b/samples/api-reference-doc-snippets/instance.js @@ -82,11 +82,7 @@ const snippets = { const projectId = await instanceAdminClient.getProjectId(); const appProfile = { - name: instanceAdminClient.appProfilePath( - projectId, - instanceId, - appProfileId - ), + name: `projects/${projectId}/instances/${instanceId}/appProfiles/${appProfileId}`, multiClusterRoutingUseAny: {}, }; From e752e0284d47188ea5e30953552a3b8aaa36ebef Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 10 Sep 2025 14:28:08 -0400 Subject: [PATCH 92/96] Fix the linting errors --- samples/instances.js | 3 --- samples/test/backups.js | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/samples/instances.js b/samples/instances.js index 9795d5b47..6812e0b97 100644 --- a/samples/instances.js +++ b/samples/instances.js @@ -14,9 +14,6 @@ 'use strict'; -// Imports the Google Cloud client library -const {Bigtable} = require('@google-cloud/bigtable'); - async function runInstanceOperations(instanceID, clusterID) { const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; const instanceAdminClient = new BigtableInstanceAdminClient(); diff --git a/samples/test/backups.js b/samples/test/backups.js index 8aba1c191..ab0bcbb7b 100644 --- a/samples/test/backups.js +++ b/samples/test/backups.js @@ -100,7 +100,7 @@ describe('backups', async () => { const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); const [backups] = await adminClient.listBackups({ - parent: `projects/${projectId}/instances/${instanceId}/clusters/-`, + parent: `projects/${projectId}/instances/${instance.id}/clusters/-`, }); return Promise.all( backups.map(backup => { From 6f2d632904859b161bb3c6d055aadc2ceb108238 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 10 Sep 2025 15:57:55 -0400 Subject: [PATCH 93/96] fix linting issues --- samples/api-reference-doc-snippets/instance.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/samples/api-reference-doc-snippets/instance.js b/samples/api-reference-doc-snippets/instance.js index 73a21fb2d..e4cc187f1 100644 --- a/samples/api-reference-doc-snippets/instance.js +++ b/samples/api-reference-doc-snippets/instance.js @@ -37,13 +37,10 @@ const snippets = { }; // creates a new Instance - const [newInstance, operation] = await instanceAdminClient.createInstance(options); + const [newInstance, operation] = + await instanceAdminClient.createInstance(options); // let operations = result[1]; // let apiResponse = result[2]; - }) - .catch(err => { - // Handle the error. - }); // [END bigtable_api_create_instance] }, @@ -160,7 +157,7 @@ const snippets = { // [END bigtable_api_create_table] }, - existsInstance: async (instanceId) => { + existsInstance: async instanceId => { // [START bigtable_api_exists_instance] const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; const instanceAdminClient = new BigtableInstanceAdminClient(); From f8d94faac995367157a6e5408ae73901673284f0 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 17 Sep 2025 16:41:26 -0400 Subject: [PATCH 94/96] samples for instances should include everything --- samples/instances.js | 95 +++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 40 deletions(-) diff --git a/samples/instances.js b/samples/instances.js index 6812e0b97..5d317eb1a 100644 --- a/samples/instances.js +++ b/samples/instances.js @@ -15,14 +15,13 @@ 'use strict'; async function runInstanceOperations(instanceID, clusterID) { - const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; - const instanceAdminClient = new BigtableInstanceAdminClient(); - const projectId = await instanceAdminClient.getProjectId(); - console.log('Check Instance Exists'); // [START bigtable_check_instance_exists] let instanceExists = true; try { + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); await instanceAdminClient.getInstance({ name: `projects/${projectId}/instances/${instanceID}`, }); @@ -39,6 +38,9 @@ async function runInstanceOperations(instanceID, clusterID) { // [START bigtable_create_prod_instance] // Creates a Production Instance with the ID "ssd-instance" // with cluster id "ssd-cluster", 3 nodes and location us-central1-f + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); const instanceOptions = { parent: `projects/${projectId}`, @@ -69,46 +71,60 @@ async function runInstanceOperations(instanceID, clusterID) { console.log(); //for just a new-line console.log('Listing Instances:'); - // [START bigtable_list_instances] - const [instances] = await instanceAdminClient.listInstances({ - parent: `projects/${projectId}`, - }); - instances.instances.forEach(instance => { - console.log(instance.name); - }); - // [END bigtable_list_instances] + { + // [START bigtable_list_instances] + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + const [instances] = await instanceAdminClient.listInstances({ + parent: `projects/${projectId}`, + }); + instances.instances.forEach(instance => { + console.log(instance.name); + }); + // [END bigtable_list_instances] + } console.log(); //for just a new-line console.log('Get Instance'); - // [START bigtable_get_instance] - const [instance2] = await instanceAdminClient.getInstance({ - name: `projects/${projectId}/instances/${instanceID}`, - }); - console.log(`Instance ID: ${instance2.name}`); - console.log(`Instance Meta: ${JSON.stringify(instance2.labels)}`); - // [END bigtable_get_instance] + { + // [START bigtable_get_instance] + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + const [instance2] = await instanceAdminClient.getInstance({ + name: `projects/${projectId}/instances/${instanceID}`, + }); + console.log(`Instance ID: ${instance2.name}`); + console.log(`Instance Meta: ${JSON.stringify(instance2.labels)}`); + // [END bigtable_get_instance] + } console.log(); //for just a new-line console.log('Listing Clusters...'); - // [START bigtable_get_clusters] - const [clusters] = await instanceAdminClient.listClusters({ - parent: `projects/${projectId}/instances/${instanceID}`, - }); - clusters.clusters.forEach(cluster => { - console.log(cluster.name); - }); - // [END bigtable_get_clusters] + { + // [START bigtable_get_clusters] + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); + const [clusters] = await instanceAdminClient.listClusters({ + parent: `projects/${projectId}/instances/${instanceID}`, + }); + clusters.clusters.forEach(cluster => { + console.log(cluster.name); + }); + // [END bigtable_get_clusters] + } } // Creates a Development instance with the ID "hdd-instance" // with cluster ID "hdd-cluster" and location us-central1-f // Cluster nodes should not be set while creating Development Instance async function createDevInstance(instanceID, clusterID) { + // [START bigtable_create_dev_instance] const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; const instanceAdminClient = new BigtableInstanceAdminClient(); const projectId = await instanceAdminClient.getProjectId(); - - // [START bigtable_create_dev_instance] console.log(); //for just a new-line console.log('Creating a DEVELOPMENT Instance'); // Set options to create an Instance @@ -140,14 +156,12 @@ async function createDevInstance(instanceID, clusterID) { // Delete the Instance async function deleteInstance(instanceID) { - // Creates a client - const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; - const instanceAdminClient = new BigtableInstanceAdminClient(); - const projectId = await instanceAdminClient.getProjectId(); - console.log(); //for just a new-line // [START bigtable_delete_instance] console.log('Deleting Instance'); + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); await instanceAdminClient.deleteInstance({ name: `projects/${projectId}/instances/${instanceID}`, }); @@ -157,12 +171,11 @@ async function deleteInstance(instanceID) { // Add Cluster async function addCluster(instanceID, clusterID) { - const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; - const instanceAdminClient = new BigtableInstanceAdminClient(); - const projectId = await instanceAdminClient.getProjectId(); - let instanceExists = true; try { + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); await instanceAdminClient.getInstance({ name: `projects/${projectId}/instances/${instanceID}`, }); @@ -177,6 +190,9 @@ async function addCluster(instanceID, clusterID) { console.log(); //for just a new-line console.log(`Adding Cluster to Instance ${instanceID}`); // [START bigtable_create_cluster] + const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; + const instanceAdminClient = new BigtableInstanceAdminClient(); + const projectId = await instanceAdminClient.getProjectId(); const clusterOptions = { parent: `projects/${projectId}/instances/${instanceID}`, clusterId: clusterID, @@ -197,11 +213,10 @@ async function addCluster(instanceID, clusterID) { // Delete the Cluster async function deleteCluster(instanceID, clusterID) { + // [START bigtable_delete_cluster] const {BigtableInstanceAdminClient} = require('@google-cloud/bigtable').v2; const instanceAdminClient = new BigtableInstanceAdminClient(); const projectId = await instanceAdminClient.getProjectId(); - - // [START bigtable_delete_cluster] console.log(); //for just a new-line console.log('Deleting Cluster'); await instanceAdminClient.deleteCluster({ From c97d46560e5bf1e518060b581c2aa3491b0b78eb Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Wed, 17 Sep 2025 17:24:15 -0400 Subject: [PATCH 95/96] Update the tableadmin samples to contain everythin --- samples/tableadmin.js | 557 ++++++++++++++++++++++++------------------ 1 file changed, 323 insertions(+), 234 deletions(-) diff --git a/samples/tableadmin.js b/samples/tableadmin.js index 7d3d23fc1..bb77cb105 100644 --- a/samples/tableadmin.js +++ b/samples/tableadmin.js @@ -13,293 +13,381 @@ // limitations under the License. // Imports the Google Cloud client library -const {Bigtable, GCRuleMaker} = require('@google-cloud/bigtable'); -const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; -const adminClient = new BigtableTableAdminClient(); - async function runTableOperations(instanceID, tableID) { - const bigtable = new Bigtable(); - const projectId = await adminClient.getProjectId(); - // The request will only work if the projectName doesn't contain the {{projectId}} token. - bigtable.projectName = `projects/${projectId}`; - const instance = bigtable.instance(instanceID); - const table = instance.table(tableID); + { + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const {Bigtable} = require('@google-cloud/bigtable'); + const adminClient = new BigtableTableAdminClient(); + const bigtable = new Bigtable(); + const projectId = await adminClient.getProjectId(); + // The request will only work if the projectName doesn't contain the {{projectId}} token. + bigtable.projectName = `projects/${projectId}`; + const instance = bigtable.instance(instanceID); + const table = instance.table(tableID); - // Check if table exists - console.log(); - console.log('Checking if table exists...'); - let tableExists = true; - try { - await adminClient.getTable({name: table.name}); - } catch (e) { - if (e.code === 5) { - tableExists = false; + // Check if table exists + console.log(); + console.log('Checking if table exists...'); + let tableExists = true; + try { + await adminClient.getTable({name: table.name}); + } catch (e) { + if (e.code === 5) { + tableExists = false; + } } - } - if (!tableExists) { - // Create table if does not exist - console.log(`Table does not exist. Creating table ${tableID}`); - const request = { - parent: `projects/${projectId}/instances/${instanceID}`, - tableId: tableID, - table: { - columnFamilies: { - follows: {}, + if (!tableExists) { + // Create table if does not exist + console.log(`Table does not exist. Creating table ${tableID}`); + const request = { + parent: `projects/${projectId}/instances/${instanceID}`, + tableId: tableID, + table: { + columnFamilies: { + follows: {}, + }, }, - }, - }; - await adminClient.createTable(request); - } else { - console.log('Table exists.'); + }; + await adminClient.createTable(request); + } else { + console.log('Table exists.'); + } } console.log(); console.log('Listing tables in current project...'); - // [START bigtable_list_tables] - // List tables in current project - const [tables] = await adminClient.listTables({parent: instance.name}); - tables.forEach(table => { - console.log(table.name); - }); - // [END bigtable_list_tables] + { + // [START bigtable_list_tables] + const {Bigtable} = require('@google-cloud/bigtable'); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceID); + // List tables in current project + const [tables] = await adminClient.listTables({parent: instance.name}); + tables.forEach(table => { + console.log(table.name); + }); + // [END bigtable_list_tables] + } console.log(); console.log('Printing table metadata...'); - // [START bigtable_get_table_metadata] - // Get table metadata, and apply a view to the table fields - // Supported views include ID, schema or full - // View defaults to schema if unspecified. - const options = { - view: 'id', - }; - const [tableMetadata] = await adminClient.getTable({ - name: table.name, - view: options.view, - }); - console.log(`Metadata: ${JSON.stringify(tableMetadata)}`); - // [END bigtable_get_table_metadata] + { + // [START bigtable_get_table_metadata] + // Get table metadata, and apply a view to the table fields + // Supported views include ID, schema or full + // View defaults to schema if unspecified. + const {Bigtable} = require('@google-cloud/bigtable'); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceID); + const table = instance.table(tableID); + const options = { + view: 'id', + }; + const [tableMetadata] = await adminClient.getTable({ + name: table.name, + view: options.view, + }); + console.log(`Metadata: ${JSON.stringify(tableMetadata)}`); + // [END bigtable_get_table_metadata] + } console.log(); console.log('Creating column family cf1 with max age GC rule...'); - // [START bigtable_create_family_gc_max_age] - // Create a column family with GC policy : maximum age - // where age = current time minus cell timestamp + { + // [START bigtable_create_family_gc_max_age] + // Create a column family with GC policy : maximum age + // where age = current time minus cell timestamp + const {Bigtable, GCRuleMaker} = require('@google-cloud/bigtable'); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceID); + const table = instance.table(tableID); - // Define the GC rule to retain data with max age of 5 days - const maxAgeRule = { - rule: { - maxAge: { - // Value must be atleast 1 millisecond - seconds: 60 * 60 * 24 * 5, - nanos: 0, - }, - }, - }; - let [family] = await adminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: 'cf1', - create: { - gcRule: GCRuleMaker.makeRule(maxAgeRule), + // Define the GC rule to retain data with max age of 5 days + const maxAgeRule = { + rule: { + maxAge: { + // Value must be atleast 1 millisecond + seconds: 60 * 60 * 24 * 5, + nanos: 0, }, }, - ], - }); - console.log(`Created column family ${family.name}`); - // [END bigtable_create_family_gc_max_age] + }; + const [family] = await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf1', + create: { + gcRule: GCRuleMaker.makeRule(maxAgeRule), + }, + }, + ], + }); + console.log(`Created column family ${family.name}`); + // [END bigtable_create_family_gc_max_age] + } console.log(); console.log('Creating column family cf2 with max versions GC rule...'); - // [START bigtable_create_family_gc_max_versions] - // Create a column family with GC policy : most recent N versions - // where 1 = most recent version + { + // [START bigtable_create_family_gc_max_versions] + // Create a column family with GC policy : most recent N versions + // where 1 = most recent version - // Define the GC policy to retain only the most recent 2 versions - const maxVersionsRule = { - rule: { - maxVersions: 2, - }, - }; + const {Bigtable, GCRuleMaker} = require('@google-cloud/bigtable'); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceID); + const table = instance.table(tableID); + // Define the GC policy to retain only the most recent 2 versions + const maxVersionsRule = { + rule: { + maxVersions: 2, + }, + }; - // Create a column family with given GC rule - [family] = await adminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: 'cf2', - create: { - gcRule: GCRuleMaker.makeRule(maxVersionsRule), + // Create a column family with given GC rule + const [family] = await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf2', + create: { + gcRule: GCRuleMaker.makeRule(maxVersionsRule), + }, }, - }, - ], - }); - console.log(`Created column family ${family.name}`); - // [END bigtable_create_family_gc_max_versions] + ], + }); + console.log(`Created column family ${family.name}`); + // [END bigtable_create_family_gc_max_versions] + } console.log(); console.log('Creating column family cf3 with union GC rule...'); - // [START bigtable_create_family_gc_union] - // Create a column family with GC policy to drop data that matches at least one condition. + { + // [START bigtable_create_family_gc_union] + // Create a column family with GC policy to drop data that matches at least one condition. - // Define a GC rule to drop cells older than 5 days or not the most recent version - const unionRule = { - ruleType: 'union', - maxVersions: 1, - maxAge: { - seconds: 60 * 60 * 24 * 5, - nanos: 0, - }, - }; + const {Bigtable, GCRuleMaker} = require('@google-cloud/bigtable'); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceID); + const table = instance.table(tableID); + // Define a GC rule to drop cells older than 5 days or not the most recent version + const unionRule = { + ruleType: 'union', + maxVersions: 1, + maxAge: { + seconds: 60 * 60 * 24 * 5, + nanos: 0, + }, + }; - [family] = await adminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: 'cf3', - create: { - gcRule: GCRuleMaker.makeRule(unionRule), + const [family] = await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf3', + create: { + gcRule: GCRuleMaker.makeRule(unionRule), + }, }, - }, - ], - }); - console.log(`Created column family ${family.name}`); - // [END bigtable_create_family_gc_union] + ], + }); + console.log(`Created column family ${family.name}`); + // [END bigtable_create_family_gc_union] + } console.log(); console.log('Creating column family cf4 with intersect GC rule...'); - // [START bigtable_create_family_gc_intersection] - // Create a column family with GC policy to drop data that matches all conditions + { + // [START bigtable_create_family_gc_intersection] + // Create a column family with GC policy to drop data that matches all conditions - // GC rule: Drop cells older than 5 days AND older than the most recent 2 versions - const intersectionRule = { - ruleType: 'intersection', - maxVersions: 2, - maxAge: { - seconds: 60 * 60 * 24 * 5, - nanos: 0, - }, - }; - [family] = await adminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: 'cf4', - create: { - gcRule: GCRuleMaker.makeRule(intersectionRule), - }, - }, - ], - }); - console.log(`Created column family ${family.name}`); - // [END bigtable_create_family_gc_intersection] - - console.log(); - console.log('Creating column family cf5 with a nested GC rule...'); - // [START bigtable_create_family_gc_nested] - // Create a nested GC rule: - // Drop cells that are either older than the 10 recent versions - // OR - // Drop cells that are older than a month AND older than the 2 recent versions - const nestedRule = { - ruleType: 'union', - maxVersions: 10, - rule: { + const {Bigtable, GCRuleMaker} = require('@google-cloud/bigtable'); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceID); + const table = instance.table(tableID); + // GC rule: Drop cells older than 5 days AND older than the most recent 2 versions + const intersectionRule = { ruleType: 'intersection', maxVersions: 2, maxAge: { - // one month - seconds: 60 * 60 * 24 * 30, + seconds: 60 * 60 * 24 * 5, nanos: 0, }, - }, - }; + }; + const [family] = await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf4', + create: { + gcRule: GCRuleMaker.makeRule(intersectionRule), + }, + }, + ], + }); + console.log(`Created column family ${family.name}`); + // [END bigtable_create_family_gc_intersection] + } - [family] = await adminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: 'cf5', - create: { - gcRule: GCRuleMaker.makeRule(nestedRule), + console.log(); + console.log('Creating column family cf5 with a nested GC rule...'); + { + // [START bigtable_create_family_gc_nested] + // Create a nested GC rule: + // Drop cells that are either older than the 10 recent versions + // OR + // Drop cells that are older than a month AND older than the 2 recent versions + const {Bigtable, GCRuleMaker} = require('@google-cloud/bigtable'); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceID); + const table = instance.table(tableID); + const nestedRule = { + ruleType: 'union', + maxVersions: 10, + rule: { + ruleType: 'intersection', + maxVersions: 2, + maxAge: { + // one month + seconds: 60 * 60 * 24 * 30, + nanos: 0, }, }, - ], - }); - console.log(`Created column family ${family.name}`); - // [END bigtable_create_family_gc_nested] + }; + + const [family] = await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf5', + create: { + gcRule: GCRuleMaker.makeRule(nestedRule), + }, + }, + ], + }); + console.log(`Created column family ${family.name}`); + // [END bigtable_create_family_gc_nested] + } console.log(); console.log('Printing ID and GC Rule for all column families...'); - // [START bigtable_list_column_families] - // List all families in the table with GC rules - const [tableData2] = await adminClient.getTable({ - name: table.name, - view: 'FULL', - }); - const families = tableData2.columnFamilies; - // Print ID, GC Rule for each column family - for (const familyId in families) { - const family = families[familyId]; - const metadata = JSON.stringify(family.gcRule); - console.log(`Column family: ${familyId}, Metadata: ${metadata}`); - /* Sample output: - Column family: projects/{{projectId}}/instances/my-instance/tables/my-table/columnFamilies/cf4, - Metadata: {"gcRule":{"intersection":{"rules":[{"maxAge":{"seconds":"432000","nanos":0},"rule":"maxAge"},{"maxNumVersions":2,"rule":"maxNumVersions"}]},"rule":"intersection"}} - */ + { + // [START bigtable_list_column_families] + // List all families in the table with GC rules + const {Bigtable} = require('@google-cloud/bigtable'); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceID); + const table = instance.table(tableID); + const [tableData2] = await adminClient.getTable({ + name: table.name, + view: 'FULL', + }); + const families = tableData2.columnFamilies; + // Print ID, GC Rule for each column family + for (const familyId in families) { + const family = families[familyId]; + const metadata = JSON.stringify(family.gcRule); + console.log(`Column family: ${familyId}, Metadata: ${metadata}`); + /* Sample output: + Column family: projects/{{projectId}}/instances/my-instance/tables/my-table/columnFamilies/cf4, + Metadata: {"gcRule":{"intersection":{"rules":[{"maxAge":{"seconds":"432000","nanos":0},"rule":"maxAge"},{"maxNumVersions":2,"rule":"maxNumVersions"}]},"rule":"intersection"}} + */ + } + // [END bigtable_list_column_families] } - // [END bigtable_list_column_families] console.log('\nUpdating column family cf1 GC rule...'); - // [START bigtable_update_gc_rule] - // Update the column family metadata to update the GC rule + { + // [START bigtable_update_gc_rule] + // Update the column family metadata to update the GC rule - // Update a column family GC rule - const updatedMetadata = { - rule: { - versions: 1, - }, - }; + const {Bigtable, GCRuleMaker} = require('@google-cloud/bigtable'); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceID); + const table = instance.table(tableID); + // Update a column family GC rule + const updatedMetadata = { + rule: { + versions: 1, + }, + }; - const [apiResponse] = await adminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: 'cf1', - update: { - gcRule: GCRuleMaker.makeRule(updatedMetadata.rule), + const [apiResponse] = await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf1', + update: { + gcRule: GCRuleMaker.makeRule(updatedMetadata.rule), + }, }, - }, - ], - }); - console.log(`Updated GC rule: ${JSON.stringify(apiResponse)}`); - // [END bigtable_update_gc_rule] + ], + }); + console.log(`Updated GC rule: ${JSON.stringify(apiResponse)}`); + // [END bigtable_update_gc_rule] + } console.log('\nPrint updated column family cf1 GC rule...'); - // [START bigtable_family_get_gc_rule] - // Retrieve column family metadata (Id, column family GC rule) - const [tableData] = await adminClient.getTable({ - name: table.name, - view: 'FULL', - }); - const metadata = tableData.columnFamilies['cf1'].gcRule; - console.log(`Metadata: ${JSON.stringify(metadata)}`); - // [END bigtable_family_get_gc_rule] + { + // [START bigtable_family_get_gc_rule] + const {Bigtable} = require('@google-cloud/bigtable'); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceID); + const table = instance.table(tableID); + // Retrieve column family metadata (Id, column family GC rule) + const [tableData] = await adminClient.getTable({ + name: table.name, + view: 'FULL', + }); + const metadata = tableData.columnFamilies['cf1'].gcRule; + console.log(`Metadata: ${JSON.stringify(metadata)}`); + // [END bigtable_family_get_gc_rule] + } console.log('\nDelete a column family cf2...'); - // [START bigtable_delete_family] - // Delete a column family - await adminClient.modifyColumnFamilies({ - name: table.name, - modifications: [ - { - id: 'cf2', - drop: true, - }, - ], - }); - console.log('cf2 deleted successfully\n'); - // [END bigtable_delete_family] + { + // [START bigtable_delete_family] + const {Bigtable} = require('@google-cloud/bigtable'); + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; + const adminClient = new BigtableTableAdminClient(); + const bigtable = new Bigtable(); + const instance = bigtable.instance(instanceID); + const table = instance.table(tableID); + // Delete a column family + await adminClient.modifyColumnFamilies({ + name: table.name, + modifications: [ + { + id: 'cf2', + drop: true, + }, + ], + }); + console.log('cf2 deleted successfully\n'); + // [END bigtable_delete_family] + } console.log( 'Run node $0 delete --instance [instanceID] --table [tableID] to delete the table.\n', ); @@ -308,10 +396,11 @@ async function runTableOperations(instanceID, tableID) { async function deleteTable(instanceID, tableID) { // const instanceID = "my-instance"; // const tableID = "my-bigtable-ID"; + + // [START bigtable_delete_table] const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId(); - // [START bigtable_delete_table] // Delete the entire table console.log('Delete the table.'); await adminClient.deleteTable({ From 120300775e00e2ba1f084acf2d44b1089f5ebe40 Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Thu, 18 Sep 2025 11:33:25 -0400 Subject: [PATCH 96/96] Eliminate unnecessary import --- samples/api-reference-doc-snippets/family.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/samples/api-reference-doc-snippets/family.js b/samples/api-reference-doc-snippets/family.js index fd5e3b270..91f5a652a 100644 --- a/samples/api-reference-doc-snippets/family.js +++ b/samples/api-reference-doc-snippets/family.js @@ -15,8 +15,7 @@ const snippets = { createColmFamily: async (instanceId, tableId, familyId) => { // [START bigtable_api_create_family] - const {BigtableTableAdminClient, GCRuleMaker} = - require('@google-cloud/bigtable').v2; + const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2; const adminClient = new BigtableTableAdminClient(); const projectId = await adminClient.getProjectId();