BigQuery:NodeJS客户端库时间戳错误

时间:2019-03-04 15:09:55

标签: node.js google-bigquery

我正在使用nodejs客户端将记录流式传输到BigQuery,除了时间戳字段上的某些错误之外,其他所有功能都工作正常,

错误

Cannot return an invalid timestamp value of 1551711230131000064 microseconds relative to the Unix epoch. The range of valid timestamp values is [0001-01-1 00:00:00, 9999-12-31 23:59:59.999999]; error in writing field ts

用于生成 timestamp的代码:

const ts = Date.now().toString(); // tried without toString()

要存储在BigQuery中的代码

function insertIntoTable(id, ts, url, domain) {
  console.log('ts: ', ts) // this logs the correct format 
  table.insert({
    id        : id,
    ts        : ts,
    url       : url,
    domain    : domain,
  })
  .then(data => {
    console.log(data);
  })
  .catch(err => {
    console.log(err);
  })
}

在此示例中,我记录了正确的大小时间戳-> ts: 1551711230131

该字段在表格中设置为TIMESTAMP类型。

关于可能的问题有什么想法?

1 个答案:

答案 0 :(得分:1)

尝试使用此

Date.now() / 1000

代替这个

Date.now().toString()
相关问题