-
Notifications
You must be signed in to change notification settings - Fork 211
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
Library cannot parse timestamp value "0" - Cannot convert a BigInt value to a number as PreciseDate #1353
Comments
the line that throws the error is this one: nodejs-bigquery/src/bigquery.ts Line 668 in 74aa150
PreciseDate class actually supports BigInt s.
|
The issue is that when the value comes from BigQuery, it comes as a string // This
const pd = new PreciseDate(BigInt(value) * BigInt(1000));
// Same as
const pd = new PreciseDate(BigInt("0") * BigInt(1000)); // equals to `0n` Downstream, that will result in |
This PR #1354 handles this issue, btw. (feel free to suggest any change to fit it to the code architecture) |
Yeah, the problem itself is on the This is my test code and it still fails with the PR, because the issue is on the line that I mentioned before ( nodejs-bigquery/src/bigquery.ts Line 668 in 74aa150
const sqlQuery =
`SELECT TIMESTAMP_ADD(@ts_value, INTERVAL 1 HOUR) as ts
UNION ALL
SELECT CAST('1969-12-25 00:00:00' as TIMESTAMP) as ts
UNION ALL
SELECT CAST('1970-01-01 00:00:01' as TIMESTAMP) as ts
UNION ALL
SELECT CAST('1970-01-01 00:00:00' as TIMESTAMP) as ts
`;
const options = {
query: sqlQuery,
location: 'US',
params: {ts_value: new Date()},
};
// Run the query
const [rows] = await bigquery.query(options);
console.log('Rows:');
rows.forEach(row => console.log(row.ts)); The fix that I implemented locally here is this one: 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;
} I'm adding some |
On the |
Cool 😄 Thanks @alvarowolfx! Looking forward to having it published! |
@guisalim unfortunately our releases are paused due to Google Cloud Next. Can you revert temporarily to a version before |
Environment details
@google-cloud/bigquery
version: 7.5.2Steps to reproduce
1970-01-01 00:00:00 UTC
(aka timestamp0
)getQueryResults()
to fetch the rowHere's the stack trace of the error:
After investigating the issue, I noticed that the following statement is causing the error (class
BigQueryTimestamp
>constructor
):If
value = "0"
,PreciseDate. constructor
will try to runnew Date(BigInt("0"))
, which throws an error.The issue was introduced by the client version 7.5.
Thanks!
The text was updated successfully, but these errors were encountered: