node.js - 将大对象转换为原始数据类型?
问题描述
我是使用 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
对象是什么。我期待decimal
或float
重视。这个Big
对象是什么?如何将Big
对象转换为decimal
or float
?
我仍在尝试浏览 BigQuery 文档,但我迷路了。任何指导/方向/反馈都会有所帮助。谢谢
--
我发现我可以这样做来parseFloat(row.f0_.toString())
将. 但这是最佳实践吗?Big
float
解决方案
推荐阅读
- django - Django forms date.today() 在早上没有返回正确的日期
- python - 尝试使用瓶子框架读取文件
- git - 如何使用不同的 SSH 密钥在 CircleCI 中克隆第二个 GitHub 存储库(作为主克隆或作为子模块)?
- django - 在 django 模型中上传多个档案
- etl - 记录 ETL 作业的方法
- npm - npm 脚本中与平台无关的用户
- odoo - 将 odoo v12 迁移到 v13 时图像损坏
- python - 从 Flask 服务器运行 python 脚本
- csv - 使用 PySpark 读取简单的 csv
- r - 将一个 xts 除以另一个并在过程中创建一个新的 xts / 附加问题