Skip to content

Library cannot parse timestamp value "0" - Cannot convert a BigInt value to a number as PreciseDate #1353

Closed
@guisalim

Description

@guisalim

Environment details

  • OS: OSx
  • Node.js version: 20.12.1
  • npm version: 10.5.0
  • @google-cloud/bigquery version: 7.5.2

Steps to reproduce

  1. For a given row in a BQ table, have a timestamp column value of 1970-01-01 00:00:00 UTC (aka timestamp 0)
  2. Run a query + getQueryResults() to fetch the row
 const [job] = await createQueryJob({ query: "SELECT * FROM .... " });
 const [result] = await job.getQueryResults(); // ---- Error: TypeError: Cannot convert a BigInt value to a number at PreciseDate

Here's the stack trace of the error:

at new Date (<anonymous>)
    at new PreciseDate (<{PATH}>/node_modules/@google-cloud/precise-date/build/src/index.js:95:26)
    at new BigQueryTimestamp (<{PATH}>/node_modules/@google-cloud/bigquery/build/src/bigquery.js:1339:22)
    at Function.timestamp (<{PATH}>/node_modules/@google-cloud/bigquery/build/src/bigquery.js:626:16)
    at convert (<{PATH}>/node_modules/@google-cloud/bigquery/build/src/bigquery.js:374:38)
    at <{PATH}>/node_modules/@google-cloud/bigquery/build/src/bigquery.js:310:29
    at Array.map (<anonymous>)
    at mergeSchema (<{PATH}>/node_modules/@google-cloud/bigquery/build/src/bigquery.js:301:26)
    at Array.map (<anonymous>)
    at Function.mergeSchemaWithRows_ (<{PATH}>/node_modules/@google-cloud/bigquery/build/src/bigquery.js:299:29)
    at <{PATH}>/node_modules/@google-cloud/bigquery/build/src/job.js:368:44
    at <{PATH}>/node_modules/@google-cloud/common/build/src/util.js:412:25
    at Util.handleResp (<{PATH}>/node_modules/@google-cloud/common/build/src/util.js:161:9)
    at <{PATH}>/node_modules/@google-cloud/common/build/src/util.js:534:22
    at onResponse (<{PATH}>/node_modules/retry-request/index.js:259:7)
    at <{PATH}>/node_modules/teeny-request/src/index.ts:333:11
    at processTicksAndRejections (node:internal/process/task_queues:95:5)'

After investigating the issue, I noticed that the following statement is causing the error (class BigQueryTimestamp > constructor):

// @google-cloud/bigquery/build/src/bigquery.js:1339
     pd = new precise_date_1.PreciseDate(BigInt(value) * BigInt(1000));

If value = "0", PreciseDate. constructor will try to run new Date(BigInt("0")), which throws an error.

The issue was introduced by the client version 7.5.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: bigqueryIssues related to the googleapis/nodejs-bigquery API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions