首页 > 解决方案 > 将大对象转换为原始数据类型?

问题描述

我是使用 BigQuery 和 NodeJS 的新手。我用这个命令安装了客户端库npm install --save @google-cloud/bigquery。然后我设置了我的凭据和 API 密钥。然后我做了一个app.js,内容如下:

// Import the Google Cloud client library using default credentials
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
async function query() {
  // Queries the U.S. given names dataset for the state of Texas.

  const query = `SELECT AVG(vs)
FROM \`vertical-idea-303617.somedb.testdata\`
WHERE d >= '2021-01-11 18:14:00' AND d < '2021-01-11 21:14:00'
GROUP BY bId, cId, EXTRACT(YEAR FROM d), EXTRACT(MONTH FROM d), EXTRACT(DAY FROM d), EXTRACT(HOUR FROM d), EXTRACT(MINUTE FROM d)`;

  // For all options, see https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query
  const options = {
    query: query,
    // Location must match that of the dataset(s) referenced in the query.
    location: 'US',
  };

  // Run the query as a job
  const [job] = await bigquery.createQueryJob(options);
  console.log(`Job ${job.id} started.`);

  // Wait for the query to finish
  const [rows] = await job.getQueryResults();

  // Print the results
  console.log('Rows:');
  rows.forEach(row => {
    console.log(row);
  });
}
query();

当我运行时node app.js,我得到如下结果:

Job ae0c6e3d-a41f-4ffe-b51e-087ab25cda2d started.
Rows:
{ f0_:
   Big {
     s: 1,
     e: 2,
     c: [ 5, 2, 4, 8 ],
     constructor:
      { [Function: Big]
        DP: 20,
        RM: 1,
        NE: -7,
        PE: 21,
        strict: false,
        Big: [Circular],
        default: [Circular] } } }
{ f0_:
   Big {
     s: 1,
     e: 2,
     c: [ 1, 1, 3, 5 ],
     constructor:
      { [Function: Big]
        DP: 20,
        RM: 1,
        NE: -7,
        PE: 21,
        strict: false,
        Big: [Circular],
        default: [Circular] } } }
etc...

我不明白Big对象是什么。我期待decimalfloat重视。这个Big对象是什么?如何将Big对象转换为decimalor float

我仍在尝试浏览 BigQuery 文档,但我迷路了。任何指导/方向/反馈都会有所帮助。谢谢

--

我发现我可以这样做来parseFloat(row.f0_.toString())将. 但这是最佳实践吗?Bigfloat

标签: node.jsgoogle-bigquery

解决方案


推荐阅读