【问题标题】:google cloud BigQuery REST API, table creation with expirationTime谷歌云 BigQuery REST API,使用过期时间创建表
【发布时间】:2015-10-27 21:17:19
【问题描述】:

我在我的 appengine 项目中使用 BigQuery API 创建表,然后使用 insertAll 流式输入法加载数据。 [参考:https://cloud.google.com/bigquery/docs/reference/v2/tables/insert]

创建表的示例python代码:

scope = "https://www.googleapis.com/auth/bigquery"
authorization_token, _ = app_identity.get_access_token(scope)
Bodyfields = {
                "kind": "bigquery#table",
                "tableReference": {
                    "projectId": BIGQUERY_PROJECTID,
                    "datasetId": BIGQUERY_DATASETID,
                    "tableId": BIGQUERY_TABLEID
                },
                "friendlyName": 'Table 1',
                "description": 'My first table in big query',
                "schema": {
                    "fields": [
                        {
                            "name": 'A',
                            "type": 'STRING'
                        },
                        {
                            "name": 'B',
                            "type": 'STRING'
                        }
                    ]
                }
            }
result = urlfetch.fetch(url="https://www.googleapis.com/bigquery/v2/projects/" + BIGQUERY_PROJECTID + "/datasets/" + BIGQUERY_DATASETID + "/tables", method=urlfetch.POST, payload=json.dumps(Bodyfields), headers = {'Content-Type': 'application/json', "Authorization": "Bearer " + authorization_token})
logging.info(result.content)

这按预期工作,但不幸的是,表的“过期时间”设置为 1 天。

根据文档,当 requestBody 中未提供 expireTime 时,表将无限期地持久化。 [参考:https://cloud.google.com/bigquery/docs/reference/v2/tables#expirationTime]。如图所示,我的桌子将在 1 天后到期。

所以我修改了代码,在插入表方法的 requestBody 中包含“expirationTime”。

代码示例:

ist_one_year_later = datetime.now() + timedelta(weeks=52)
ist_one_year_later_epoch_timestamp = long(float((ist_one_year_later - datetime(1970,1,1)).total_seconds()))
scope = "https://www.googleapis.com/auth/bigquery"
authorization_token, _ = app_identity.get_access_token(scope)
Bodyfields = {
                "kind": "bigquery#table",
                "tableReference": {
                    "projectId": BIGQUERY_PROJECTID,
                    "datasetId": BIGQUERY_DATASETID,
                    "tableId": BIGQUERY_TABLEID
                },
                "friendlyName": 'Table 1',
                "description": 'My first table in big query',,
                "expirationTime": ist_one_year_later_epoch_timestamp,
                "schema": {
                    "fields": [
                        {
                            "name": 'A',
                            "type": 'STRING'
                        },
                        {
                            "name": 'B',
                            "type": 'STRING'
                        }
                    ]
                }
            }
result = urlfetch.fetch(url="https://www.googleapis.com/bigquery/v2/projects/" + BIGQUERY_PROJECTID + "/datasets/" + BIGQUERY_DATASETID + "/tables", method=urlfetch.POST, payload=json.dumps(Bodyfields), headers = {'Content-Type': 'application/json', "Authorization": "Bearer " + authorization_token})
logging.info(result.content)

现在的结果更加离奇。这个请求的响应,说表已创建。但是当我尝试列出数据集中的表时,该表不可用。

有人能告诉我如何将表的过期时间设置为从创建时间开始的 1 年吗?

编辑:我已经尝试了补丁和更新方法。两者都没有给出任何错误,但也没有延长过期时间。

【问题讨论】:

  • 这对我来说似乎是一个错误。在此处填写错误报告:code.google.com/p/google-bigquery/issues/entry
  • @Pentium10 我已经提交了一个错误报告。同时,有什么解决方法可以为我们当前的项目制作一个具有更长过期时间的表
  • 从界面创建表,我觉得这样你就没有这个问题了
  • 创建的数据集是否为其表设置了默认过期时间?
  • @FelipeHoffa 谢谢。那是一个很好的收获。是的,我在测试阶段通过勾选“1 天内到期”复选框创建了数据集。但即便如此,根据文档,当我向新表提供过期时间时,它必须覆盖数据集的设置。希望谷歌的人可以修复这个错误。现在,我可以通过创建一个新数据集来解决我的问题。谢谢

标签: google-app-engine google-bigquery


【解决方案1】:

根据您问题中的 cmets,创建的没有过期时间的表会从您的数据集中使用一天的默认过期时间。

您创建具有明确过期时间的表的代码不正确。根据https://cloud.google.com/bigquery/docs/reference/v2/tables#expirationTime,到期时间以毫秒为单位,但您提供了自纪元以来的秒数。因此,表已成功创建,过期时间已过去,并且在您列出数据集中的表时不存在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-14
    • 2014-10-30
    • 1970-01-01
    • 2023-01-25
    • 2012-05-13
    • 1970-01-01
    • 2017-08-20
    • 1970-01-01
    相关资源
    最近更新 更多