diff --git a/src/table.ts b/src/table.ts index dae1ef04..c555e41e 100644 --- a/src/table.ts +++ b/src/table.ts @@ -373,6 +373,12 @@ class Table extends ServiceObject { * is normally required for the `create` method must be contained within * this object as well. * + * If you wish to get a selection of metadata instead of the full table metadata + * (retrieved by both Table#get by default and by Table#getMetadata), use + * the `options` parameter to set the `view` and/or `selectedFields` query parameters. + * + * See {@link https://cloud.google.com/bigquery/docs/reference/rest/v2/tables/get#TableMetadataView| Tables.get and TableMetadataView } + * * @method Table#get * @param {options} [options] Configuration object. * @param {boolean} [options.autoCreate=false] Automatically create the @@ -392,10 +398,18 @@ class Table extends ServiceObject { * * const table = dataset.table('my-table'); * + * const options = { + * view: "BASIC" + * } + * * table.get((err, table, apiResponse) => { * // `table.metadata` has been populated. * }); * + * table.get(options, (err, table, apiResponse) => { + * // A selection of `table.metadata` has been populated + * }) + * * //- * // If the callback is omitted, we'll return a Promise. * //- diff --git a/system-test/bigquery.ts b/system-test/bigquery.ts index fb6b3f39..390f9e3c 100644 --- a/system-test/bigquery.ts +++ b/system-test/bigquery.ts @@ -866,7 +866,6 @@ describe('BigQuery', () => { stream .pipe(table.createInsertStream()) .on('response', (response: InsertRowsStreamResponse) => { - console.log(response); assert.deepStrictEqual(response.kind, expectedResponse); done(); }); @@ -888,9 +887,32 @@ describe('BigQuery', () => { const description = 'catsandstuff'; await table.setMetadata({description}); const [metadata] = await table.getMetadata(); + const metadataProps = Object.keys(metadata); + assert.strictEqual(metadataProps.includes('numBytes'), true); + assert.notStrictEqual(metadata.numBytes, undefined); + assert.strictEqual(metadataProps.includes('lastModifiedTime'), true); + assert.notStrictEqual(metadata.lastModifiedTime, undefined); assert.strictEqual(metadata.description, description); }); + it('should set & get partial metadata', async () => { + const options = { + view: 'BASIC', + }; + const [basicMetadata] = await table.get(options); + const basicMetadataProps = Object.values( + Object.keys(basicMetadata.metadata) + ); + + assert.strictEqual(basicMetadataProps.includes('numBytes'), false); + assert.strictEqual(basicMetadata.metadata.numBytes, undefined); + assert.strictEqual( + basicMetadataProps.includes('lastModifiedTime'), + false + ); + assert.strictEqual(basicMetadata.metadata.lastModifiedTime, undefined); + }); + describe('copying', () => { interface TableItem { data?: {tableId?: number};