Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: partial metadata projection #1258

Merged
merged 6 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
bigQuery: BigQuery;
location?: string;
rowQueue?: RowQueue;
createReadStream(options?: GetRowsOptions): ResourceStream<RowMetadata> {

Check warning on line 223 in src/table.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<RowMetadata>({}, () => {});
}
Expand Down Expand Up @@ -373,6 +373,12 @@
* 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 @@
*
* 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
Original file line number Diff line number Diff line change
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
Loading