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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parsing zero value timestamp #1355

Merged
merged 2 commits into from
Apr 9, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/bigquery.ts
Expand Up @@ -331,17 +331,17 @@
private _universeDomain: string;
private _enableQueryPreview: boolean;

createQueryStream(options?: Query | string): ResourceStream<RowMetadata> {

Check warning on line 334 in src/bigquery.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>({}, () => {});
}

getDatasetsStream(options?: GetDatasetsOptions): ResourceStream<Dataset> {

Check warning on line 339 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<Dataset>({}, () => {});
}

getJobsStream(options?: GetJobsOptions): ResourceStream<Job> {

Check warning on line 344 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<Job>({}, () => {});
}
Expand Down Expand Up @@ -665,7 +665,8 @@
break;
}
case 'TIMESTAMP': {
const pd = new PreciseDate(BigInt(value) * BigInt(1000));
const pd = new PreciseDate();
pd.setFullTime(PreciseDate.parseFull(BigInt(value) * BigInt(1000)));
value = BigQuery.timestamp(pd);
break;
}
Expand Down Expand Up @@ -1550,7 +1551,7 @@
const parameterMode = is.array(params) ? 'positional' : 'named';
const queryParameters: bigquery.IQueryParameter[] = [];
if (parameterMode === 'named') {
const namedParams = params as {[param: string]: any};

Check warning on line 1554 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
for (const namedParameter of Object.getOwnPropertyNames(namedParams)) {
const value = namedParams[namedParameter];
let queryParameter;
Expand Down Expand Up @@ -2193,7 +2194,7 @@

options = extend({job}, queryOpts, options);
if (res && res.jobComplete) {
let rows: any = [];

Check warning on line 2197 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
if (res.schema && res.rows) {
rows = BigQuery.mergeSchemaWithRows_(res.schema, res.rows, {
wrapIntegers: options.wrapIntegers || false,
Expand Down
32 changes: 32 additions & 0 deletions test/bigquery.ts
Expand Up @@ -639,6 +639,38 @@ describe('BigQuery', () => {
});
});

it('should parse uint64 timestamps with nanosecond precision', () => {
const SCHEMA_OBJECT = {
fields: [{name: 'ts', type: 'TIMESTAMP'}],
} as {fields: TableField[]};

sandbox.restore(); // restore BigQuery.timestamp call

const rows = {
raw: [
{f: [{v: '-604800000000'}]}, // negative value
{f: [{v: '0'}]}, // 0 value
{f: [{v: '1000000'}]}, // 1 sec after epoch
{f: [{v: '1712609904434123'}]}, // recent time
],
expectedParsed: [
{ts: BigQuery.timestamp('1969-12-25T00:00:00.000Z')},
{ts: BigQuery.timestamp('1970-01-01T00:00:00Z')},
{ts: BigQuery.timestamp('1970-01-01T00:00:01Z')},
{ts: BigQuery.timestamp('2024-04-08T20:58:24.434123Z')},
],
};

const mergedRows = BigQuery.mergeSchemaWithRows_(
SCHEMA_OBJECT,
rows.raw,
{}
);
mergedRows.forEach((mergedRow: {}, i: number) => {
assert.deepStrictEqual(mergedRow, rows.expectedParsed[i]);
});
});

it('should wrap integers with option', () => {
const wrapIntegersBoolean = true;
const wrapIntegersObject = {};
Expand Down