gpt4 book ai didi

firebase - 当 Firebase Functions 发送时,Timestamp 在 BigQuery 上返回错误

转载 作者:行者123 更新时间:2023-12-05 05:16:56 29 4
gpt4 key购买 nike

我正在尝试从 Firebase Functions 向 BigQuery 发送时间戳字段。我正在发送 admin.firestore.FieldValue.serverTimestamp()并且 BigQuery 上的字段是 TIMESTAMP 类型。

我收到一个错误:

table.insert: {"errors":[{"errors":[{"message":"This field is not a record.","reason":"invalid"}]}],"response":{"kind":"bigquery#tableDataInsertAllResponse","insertErrors":[{"index":0,"errors":[{"reason":"invalid","location":"datetime","debugInfo":"","message":"This field is not a record."}]}]},"message":"A failure occurred during this request."}

我的代码是:

exports.sessionsToBQ = functions.firestore
.document("/Users/{userId}/Sessions/{sessionId}")
.onWrite((change, context) => {

const dataset = bigquery.dataset('App');
const table = dataset.table('Sessions');
tableName = 'Sessions'
datasetName = 'App'

dataset.exists().catch(err => {
console.error(
`dataset.exists: dataset ${datasetName} does not exist: ${JSON.stringify(
err
)}`
)
return err
})

//let table = dataset.table(tableName)
table.exists().catch(err => {
console.error(
`table.exists: table ${tableName} does not exist: ${JSON.stringify(
err
)}`
)
return err
})

let row = {
insertId: context.params.sessionId,
json: {
sessionId: context.params.sessionId,
userId: context.params.userId,
datetime: admin.firestore.FieldValue.serverTimestamp(),
duration: change.after.data().duration,
distance: change.after.data().distance,
IP: change.after.data().IP
},
}

return table.insert(row, { raw: true }).catch(err => {
console.error(`table.insert: ${JSON.stringify(err)}`)
return err
})
})

我做错了什么?如何正确发送当前时间戳到大查询?

最佳答案

问题已解决,通过更改

admin.firestore.FieldValue.serverTimestamp()

Math.floor(Date.now() / 1000)

关于firebase - 当 Firebase Functions 发送时,Timestamp 在 BigQuery 上返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49881487/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com