将大对象转换为原始数据类型?

时间:2021-02-11 15:10:12

标签: node.js google-bigquery

我刚开始使用 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 对象转换为 decimalfloat

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

--

我发现我可以这样做 parseFloat(row.f0_.toString())Big 转换为 float。但这是最佳做法吗?

0 个答案:

没有答案
相关问题