【问题标题】:How to set expiration time for a new table in BigQuery created from Google Apps Script?如何为从 Google Apps 脚本创建的 BigQuery 中的新表设置过期时间?
【发布时间】:2020-11-07 03:53:14
【问题描述】:

我有一个脚本可以从 Google Apps 脚本项目中创建新的 Google BigQuery 表。 当我使用默认到期时间运行它时,它运行良好。 但现在我想将过期时间设置为 2 小时(7200000 毫秒)

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。 我错在哪里以及如何解决?

【问题讨论】:

  • 如果你发送7200000而不是"7200000"会发生什么?

标签: google-apps-script google-bigquery


【解决方案1】:

问题:

您应该提供自纪元以来的毫秒数,而不是自当前时刻以来的毫秒数。来自 BigQuery table resource docs

到期时间:可选。此表的过期时间,自纪元以来的毫秒数

解决办法:

获取从纪元到现在的毫秒数,并将两个小时添加到此:

var expirationTime = 7200000 + new Date().getTime();

如有必要,在设置请求正文时将其解析为字符串:expirationTime: expirationTime.toString()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多