Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
laljikanjareeya committed Jun 12, 2020
1 parent 00c6e71 commit bfb74ad
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/table.ts
Expand Up @@ -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();

Expand Down
30 changes: 30 additions & 0 deletions test/table.ts
Expand Up @@ -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);
});
Expand Down

0 comments on commit bfb74ad

Please sign in to comment.