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: switch timestamp representation to int64 usec #1332

Merged
merged 6 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: properly handle number input
  • Loading branch information
alvarowolfx committed Feb 16, 2024
commit c543b26e323677427744929680695e61e1b3b246
3 changes: 3 additions & 0 deletions src/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,17 @@
location?: string;
private _universeDomain: string;

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

Check warning on line 322 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 327 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 332 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 @@ -2219,7 +2219,10 @@
} else {
pd = new PreciseDate(BigInt(value) * BigInt(1000));
}
} else if (value > 0) {
pd = new PreciseDate(BigInt(value) * BigInt(1000));
} else {
// Nan or negative values - invalid dates
alvarowolfx marked this conversation as resolved.
Show resolved Hide resolved
pd = new PreciseDate(value);
alvarowolfx marked this conversation as resolved.
Show resolved Hide resolved
}
// to keep backward compatibility, only converts with microsecond
Expand Down
11 changes: 11 additions & 0 deletions test/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,17 @@
assert.strictEqual(timestamp.value, EXPECTED_VALUE);
});

it('should accept a number in microseconds', () => {
const ms = INPUT_PRECISE_DATE.valueOf(); // milliseconds
const us = (ms*1000) + INPUT_PRECISE_DATE.getMicroseconds(); // microseconds

Check failure on line 886 in test/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `(ms*1000)` with `ms·*·1000`
let timestamp = bq.timestamp(us);
assert.strictEqual(timestamp.value, EXPECTED_VALUE_MICROS);

const usStr = `${us}`;
timestamp = bq.timestamp(usStr);
assert.strictEqual(timestamp.value, EXPECTED_VALUE_MICROS);
});

it('should accept a string with microseconds', () => {
const timestamp = bq.timestamp(INPUT_STRING_MICROS);
assert.strictEqual(timestamp.value, EXPECTED_VALUE_MICROS);
Expand Down