Skip to content

Commit d433711

Browse files
authored
fix: parsing zero value timestamp (#1355)
1 parent 74aa150 commit d433711

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/bigquery.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,8 @@ export class BigQuery extends Service {
665665
break;
666666
}
667667
case 'TIMESTAMP': {
668-
const pd = new PreciseDate(BigInt(value) * BigInt(1000));
668+
const pd = new PreciseDate();
669+
pd.setFullTime(PreciseDate.parseFull(BigInt(value) * BigInt(1000)));
669670
value = BigQuery.timestamp(pd);
670671
break;
671672
}

test/bigquery.ts

+32
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,38 @@ describe('BigQuery', () => {
639639
});
640640
});
641641

642+
it('should parse uint64 timestamps with nanosecond precision', () => {
643+
const SCHEMA_OBJECT = {
644+
fields: [{name: 'ts', type: 'TIMESTAMP'}],
645+
} as {fields: TableField[]};
646+
647+
sandbox.restore(); // restore BigQuery.timestamp call
648+
649+
const rows = {
650+
raw: [
651+
{f: [{v: '-604800000000'}]}, // negative value
652+
{f: [{v: '0'}]}, // 0 value
653+
{f: [{v: '1000000'}]}, // 1 sec after epoch
654+
{f: [{v: '1712609904434123'}]}, // recent time
655+
],
656+
expectedParsed: [
657+
{ts: BigQuery.timestamp('1969-12-25T00:00:00.000Z')},
658+
{ts: BigQuery.timestamp('1970-01-01T00:00:00Z')},
659+
{ts: BigQuery.timestamp('1970-01-01T00:00:01Z')},
660+
{ts: BigQuery.timestamp('2024-04-08T20:58:24.434123Z')},
661+
],
662+
};
663+
664+
const mergedRows = BigQuery.mergeSchemaWithRows_(
665+
SCHEMA_OBJECT,
666+
rows.raw,
667+
{}
668+
);
669+
mergedRows.forEach((mergedRow: {}, i: number) => {
670+
assert.deepStrictEqual(mergedRow, rows.expectedParsed[i]);
671+
});
672+
});
673+
642674
it('should wrap integers with option', () => {
643675
const wrapIntegersBoolean = true;
644676
const wrapIntegersObject = {};

0 commit comments

Comments
 (0)