Skip to content

Commit

Permalink
feat: partial metadata projection (#1258)
Browse files Browse the repository at this point in the history
* changing system tests and updating types

* preliminary type interface changes

* complete documentation and system-test changes

* updating system-tests for getting metadata
  • Loading branch information
loferris committed Aug 15, 2023
1 parent 10e151f commit b70d3a4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/table.ts
Expand Up @@ -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
Expand All @@ -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.
* //-
Expand Down
24 changes: 23 additions & 1 deletion system-test/bigquery.ts
Expand Up @@ -866,7 +866,6 @@ describe('BigQuery', () => {
stream
.pipe(table.createInsertStream())
.on('response', (response: InsertRowsStreamResponse) => {
console.log(response);
assert.deepStrictEqual(response.kind, expectedResponse);
done();
});
Expand All @@ -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};
Expand Down

0 comments on commit b70d3a4

Please sign in to comment.