我有一个脚本,可以创建来自Google Apps脚本项目的新Google BigQuery表。 当我使用默认到期时间运行它时,它运行良好。 但是现在我想将到期时间设置为2小时(7200000ms)
function createNewTable(tableId){
var table = {
expirationTime: "7200000",
tableReference: {
projectId: projectId,
datasetId: datasetId,
tableId: tableId
}
}
table = BigQuery.Tables.insert(table, projectId, datasetId);
console.info('Table created: %s', table.id);
}
它不起作用,因为错误API call to bigquery.tables.insert failed with error: Expiration time must be at least 1 seconds in the future
。
我在哪里出错以及如何解决?
答案 0 :(得分:2)
您应该提供自纪元以来的毫秒数,而不是当前时刻。来自BigQuery table resource docs:
到期时间:可选。该表过期的时间,
自该纪元以来的毫秒数。
获取自大纪元到当前时刻的毫秒数,并将其加上两个小时:
var expirationTime = 7200000 + new Date().getTime();
如有必要,在设置请求正文expirationTime: expirationTime.toString()
时将其解析为字符串。