Skip to content

Commit bfb74ad

Browse files
fix: load job to a different project ID (#748)
* fix: load job to a different project ID Co-authored-by: Benjamin E. Coe <bencoe@google.com>
1 parent 00c6e71 commit bfb74ad

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

src/table.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -1373,13 +1373,17 @@ class Table extends common.ServiceObject {
13731373
metadata.schema = Table.createSchemaFromString_(metadata.schema);
13741374
}
13751375

1376-
extend(true, metadata, {
1377-
destinationTable: {
1378-
projectId: this.bigQuery.projectId,
1379-
datasetId: this.dataset.id,
1380-
tableId: this.id,
1376+
metadata = extend(
1377+
true,
1378+
{
1379+
destinationTable: {
1380+
projectId: this.bigQuery.projectId,
1381+
datasetId: this.dataset.id,
1382+
tableId: this.id,
1383+
},
13811384
},
1382-
});
1385+
metadata
1386+
);
13831387

13841388
let jobId = metadata.jobId || uuid.v4();
13851389

test/table.ts

+30
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,36 @@ describe('BigQuery/Table', () => {
15071507
table.createWriteStream_({schema: SCHEMA_STRING}).emit('writing');
15081508
});
15091509

1510+
it('should override destination table', done => {
1511+
const expectedMetadata = {
1512+
destinationTable: {
1513+
projectId: 'projectId-override',
1514+
datasetId: 'datasetId-override',
1515+
tableId: 'tableId-override',
1516+
},
1517+
};
1518+
makeWritableStreamOverride = (
1519+
stream: stream.Stream,
1520+
options: MakeWritableStreamOptions
1521+
) => {
1522+
assert.deepStrictEqual(
1523+
options.metadata.configuration?.load?.destinationTable,
1524+
expectedMetadata.destinationTable
1525+
);
1526+
done();
1527+
};
1528+
1529+
table
1530+
.createWriteStream_({
1531+
destinationTable: {
1532+
projectId: 'projectId-override',
1533+
datasetId: 'datasetId-override',
1534+
tableId: 'tableId-override',
1535+
},
1536+
})
1537+
.emit('writing');
1538+
});
1539+
15101540
it('should return a stream', () => {
15111541
assert(table.createWriteStream_() instanceof stream.Stream);
15121542
});

0 commit comments

Comments
 (0)