From bfb74add1850925837fa1737fded8642c80f0356 Mon Sep 17 00:00:00 2001 From: Lalji Kanjareeya <46327204+laljikanjareeya@users.noreply.github.com> Date: Fri, 12 Jun 2020 07:55:24 +0530 Subject: [PATCH] fix: load job to a different project ID (#748) * fix: load job to a different project ID Co-authored-by: Benjamin E. Coe --- src/table.ts | 16 ++++++++++------ test/table.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/table.ts b/src/table.ts index f6ac9ac6..99eaf3e8 100644 --- a/src/table.ts +++ b/src/table.ts @@ -1373,13 +1373,17 @@ class Table extends common.ServiceObject { metadata.schema = Table.createSchemaFromString_(metadata.schema); } - extend(true, metadata, { - destinationTable: { - projectId: this.bigQuery.projectId, - datasetId: this.dataset.id, - tableId: this.id, + metadata = extend( + true, + { + destinationTable: { + projectId: this.bigQuery.projectId, + datasetId: this.dataset.id, + tableId: this.id, + }, }, - }); + metadata + ); let jobId = metadata.jobId || uuid.v4(); diff --git a/test/table.ts b/test/table.ts index 304a333f..d5588a54 100644 --- a/test/table.ts +++ b/test/table.ts @@ -1507,6 +1507,36 @@ describe('BigQuery/Table', () => { table.createWriteStream_({schema: SCHEMA_STRING}).emit('writing'); }); + it('should override destination table', done => { + const expectedMetadata = { + destinationTable: { + projectId: 'projectId-override', + datasetId: 'datasetId-override', + tableId: 'tableId-override', + }, + }; + makeWritableStreamOverride = ( + stream: stream.Stream, + options: MakeWritableStreamOptions + ) => { + assert.deepStrictEqual( + options.metadata.configuration?.load?.destinationTable, + expectedMetadata.destinationTable + ); + done(); + }; + + table + .createWriteStream_({ + destinationTable: { + projectId: 'projectId-override', + datasetId: 'datasetId-override', + tableId: 'tableId-override', + }, + }) + .emit('writing'); + }); + it('should return a stream', () => { assert(table.createWriteStream_() instanceof stream.Stream); });