【问题标题】:Google BigQuery table Patch/Update doesn't workGoogle BigQuery 表补丁/更新不起作用
【发布时间】:2014-04-07 13:59:20
【问题描述】:
Google_Http_Request object {
  batchHeaders => array(3) (
    [Content-Type] => (string) application/http
    [Content-Transfer-Encoding] => (string) binary
    [MIME-Version] => (string) 1.0
  )
  queryParams => array(0)
  requestMethod => (string) PATCH
  requestHeaders => array(3) (
    [content-type] => (string) application/json; charset=UTF-8
    [authorization] => (string) *edited*
    [accept-encoding] => (string) gzip
  )
  baseComponent => (string) https://www.googleapis.com
  path => (string) /bigquery/v2/projects/aerobic-forge-504/datasets/wr_dev/tables/user_profile
  postBody => (string) [{"name":"user_id","type":"integer","mode":"nullable"},{"name":"is_complete","type":"integer","mode":"nullable"},{"name":"country_id","type":"integer","mode":"nullable"},{"name":"state","type":"string","mode":"nullable"},{"name":"city","type":"string","mode":"nullable"},{"name":"zip","type":"string","mode":"nullable"},{"name":"language","type":"string","mode":"nullable"},{"name":"industry_id","type":"integer","mode":"nullable"},{"name":"subscribed_status","type":"integer","mode":"nullable"},{"name":"tracking_prod_type","type":"string","mode":"nullable"},{"name":"tracking_prod_id","type":"integer","mode":"nullable"},{"name":"timestamp","type":"timestamp","mode":"required"},{"name":"tags","type":"string","mode":"repeated"},{"name":"utm","type":"record","mode":"nullable","fields":[{"name":"source","type":"string","mode":"nullable"},{"name":"medium","type":"string","mode":"nullable"},{"name":"campaign","type":"string","mode":"nullable"},{"name":"content","type":"string","mode":"nullable"},{"name":"term","type":"string","mode":"nullable"}]},{"name":"meta","type":"string","mode":"nullable"}]
  userAgent => (string) Client_Library_Examples google-api-php-client/1.0.3-beta (gzip)
  canGzip => (bool) true
  responseHttpCode => null
  responseHeaders => null
  responseBody => null
  expectedClass => (string) Google_Service_Bigquery_Table
  accessKey => null
}

我有这个调用,它返回成功,但所需的更改没有反映在架构上。 tracking_prod_type 是一个新字段,它没有添加到架构中。我们尝试了PatchUpdate 方式,但我们无法添加额外的列。更新返回:Provided Schema does not match。补丁返回有效。

在 postBody 上,我们尝试了不同的语法,但都不起作用。 [etag] => (string) "wRHWmN_1J7FEq2j8vIkltiyoyRw/GVGxfUY15UK1iZLhzZzfWOf-1Ow"

我们尝试关注这个问答Bigquery add columns to table schema

当我们发出调用时,我们看到表架构上的 Last Modified 字段被修改,但结构没有新列。

更新

Google_Http_Request object {
  batchHeaders => array(3) (
    [Content-Type] => (string) application/http
    [Content-Transfer-Encoding] => (string) binary
    [MIME-Version] => (string) 1.0
  )
  queryParams => array(0)
  requestMethod => (string) PATCH
  requestHeaders => array(2) (
    [content-type] => (string) application/json; charset=UTF-8
    [authorization] => (string) edited
  )
  baseComponent => (string) https://www.googleapis.com
  path => (string) /bigquery/v2/projects/aerobic-forge-504/datasets/wr_dev/tables/user_profile
  postBody => (string) {"fields":[{"name":"user_id","type":"integer","mode":"nullable"},{"name":"is_complete","type":"integer","mode":"nullable"},{"name":"country_id","type":"integer","mode":"nullable"},{"name":"state","type":"string","mode":"nullable"},{"name":"city","type":"string","mode":"nullable"},{"name":"zip","type":"string","mode":"nullable"},{"name":"language","type":"string","mode":"nullable"},{"name":"industry_id","type":"integer","mode":"nullable"},{"name":"subscribed_status","type":"integer","mode":"nullable"},{"name":"timestamp","type":"timestamp","mode":"required"},{"name":"tags","type":"string","mode":"repeated"},{"name":"utm","type":"record","mode":"nullable","fields":[{"name":"source","type":"string","mode":"nullable"},{"name":"medium","type":"string","mode":"nullable"},{"name":"campaign","type":"string","mode":"nullable"},{"name":"content","type":"string","mode":"nullable"},{"name":"term","type":"string","mode":"nullable"}]},{"name":"meta","type":"string","mode":"nullable"},{"name":"tracking_prod_type","type":"string","mode":"nullable"},{"name":"tracking_prod_id","type":"integer","mode":"nullable"}]}
  userAgent => null
  canGzip => null
  responseHttpCode => nu...

使用补丁更新2

这是当我有 tableResource 和 schema,并使用 PATCH 的时候。架构中列出的两个附加列。我得到了:Provided Schema does not match Table aerobic-forge-504:wr_dev.user_profile

Google_Http_Request object {
  batchHeaders => array(3) (
    [Content-Type] => (string) application/http
    [Content-Transfer-Encoding] => (string) binary
    [MIME-Version] => (string) 1.0
  )
  queryParams => array(0)
  requestMethod => (string) PATCH
  requestHeaders => array(3) (
    [content-type] => (string) application/json; charset=UTF-8
    [authorization] => (string) edited
    [accept-encoding] => (string) gzip
  )
  baseComponent => (string) https://www.googleapis.com
  path => (string) /bigquery/v2/projects/aerobic-forge-504/datasets/wr_dev/tables/user_profile
  postBody => (string) {"tableReference":{"datasetId":"wr_dev","projectId":"aerobic-forge-504","tableId":"user_profile"},"schema":{"fields":[{"name":"user_id","type":"integer","mode":"nullable"},{"name":"is_complete","type":"integer","mode":"nullable"},{"name":"country_id","type":"integer","mode":"nullable"},{"...

使用 PUT 更新3

当使用更新节点时,我仍然得到Provided Schema does not match Table aerobic-forge-504:wr_dev.user_profile

Google_Http_Request object {
  batchHeaders => array(3) (
    [Content-Type] => (string) application/http
    [Content-Transfer-Encoding] => (string) binary
    [MIME-Version] => (string) 1.0
  )
  queryParams => array(0)
  requestMethod => (string) PUT
  requestHeaders => array(4) (
    [content-type] => (string) application/json; charset=UTF-8
    [authorization] => (string) edited
    [accept-encoding] => (string) gzip
    [content-length] => (int) 1221
  )
  baseComponent => (string) https://www.googleapis.com
  path => (string) /bigquery/v2/projects/aerobic-forge-504/datasets/wr_dev/tables/user_profile
  postBody => (string) {"tableReference":{"datasetId":"wr_dev","projectId":"aerobic-forge-504","tableId":"user_profile"},"schema":{"fields":[{"name":"user_id","type":"integer","mode":"nullable"},{"name":"is_complete","type":"integer","mode":"nullable"},{"name":"country_id","type":"integer","mode":"nullable"},{"...

【问题讨论】:

    标签: php google-bigquery


    【解决方案1】:

    调用补丁或更新时,您需要提供一些看起来像表格的东西。在上面的示例中,您似乎没有传递表资源,而只是传递了表资源中的字段。您可能需要将您的 postBody 包装在 {"schema": {"fields": postBody } }

    之类的东西中

    与另一个问题相比,这有点令人困惑,因为 bq update 会为您进行包装。

    您看到更新失败的原因是 bigquery 服务器根本看不到任何架构,因此它认为您正在尝试删除架构。而patch成功了但是什么都不做,因为它根本看不到任何有效的字段,所以它只是做了一个空的patch操作。

    这是一个将字段添加到架构的 curl 会话示例。适应php应该比较容易。它使用来自here的auth.py

    PROJECT_ID=<your_project_here>
    DATASET_ID=scratch
    
    BASE_URL=https://www.googleapis.com/bigquery/v2/projects
    TABLES_URL=${BASE_URL}/${PROJECT_ID}/datasets/${DATASET_ID}/tables
    
    ### Make a scratch dataset.
    bq --project_id=${PROJECT_ID} mk –d ${DATASET_ID}
    
    SCHEMA="{'fields': [{'name':'foo', 'type': 'STRING'}]}"
    TABLE_REF="{'tableId': 'table1', \
        'datasetId': 'scratch', \
        'projectId': '${PROJECT_ID}'}"
    
    ### Make a temporary table with a schema.
    curl -H "$(python auth.py)" \
        -H "Content-Type: application/json" \
        -X POST \
        -d "{'tableReference': ${TABLE_REF}, \
             'schema': ${SCHEMA}}" \
        "${TABLES_URL}"
    
    ### Tables.update()
    SCHEMA2="{'fields': [ \
        {'name':'foo', 'type': 'STRING'}, \
        {'name': 'bar', 'type': 'FLOAT'}]}"
    TABLE_JSON="{'tableReference': ${TABLE_REF}, 'schema': ${SCHEMA2}}"
    curl -H "$(python auth.py)" \
        -H "Content-Type: application/json" \
        -X PUT \
        -d "${TABLE_JSON}" \
        "${TABLES_URL}/table1"
    
    ### Tables.patch()
    EXPIRATION_TIME=$(($(date +"%s")+24*60*60))000
    curl -H "$(python auth.py)" \
        -H "Content-Type: application/json" \
        -X PATCH \
        --data-binary "{'expirationTime': '${EXPIRATION_TIME}'}" \
        "${TABLES_URL}/table1"
    

    【讨论】:

    • 我也试过了,没声音。我会发布更多更新。
    • 其他几件事: 1. 顺序很重要。如果您更改顺序,它将看起来像一个不兼容的模式。 2. 您不能将必填字段添加到现有架构中。
    • 您的意思是,我只能在表格末尾添加新字段吗?我对旧列有哪些选择?
    • 另一方面,使用来自 github 的官方 PHP Api:从表更改为模式时,我得到了这个:可捕获的致命错误:传递给 Google_Service_Bigquery_Tables_Resource::patch() 的参数 4 必须是一个实例Google_Service_Bigquery_Table 的实例,给定的 Google_Service_Bigquery_TableSchema 实例
    • 我已经更新了问题,postBody 更改后仍然无法正常工作。见[etag] =&gt; (string) "wRHWmN_1J7FEq2j8vIkltiyoyRw/MCVd1PYApiH5Gae-WwhG1ra6WCU"
    猜你喜欢
    • 2021-12-08
    • 2015-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多