ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

PHP-Google BigQuery表补丁/更新不起作用

2019-10-12 03:42:10  阅读:136  来源: 互联网

标签:php google-bigquery


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是一个新字段,并且没有添加到架构中.我们尝试了Patch和Update方法,但无法添加其他列.更新返回:提供的架构不匹配.补丁返回有效.

在postBody上,我们尝试了不同的语法,但没有一个起作用. [etag] => (字符串)“ wRHWmN_1J7FEq2j8vIkltiyoyRw / GVGxfUY15UK1iZLhzZzfWOf-1Ow”

我们尝试遵循此Q& A Bigquery add columns to table schema

当我们发出调用时,我们看到在表模式上Last 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...

使用PATCH的update2

这是当我有tableResource和架构,并使用PATCH时.模式中列出了另外两个列.而且我得到了:提供的架构与表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

使用更新节点时,我仍然得到“提供的架构”与表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"},{"...

解决方法:

调用补丁或更新时,您需要提供类似于表的内容.在上面的示例中,您似乎没有传递表资源,只是传递了表资源中的字段.您可能需要用类似{“ schema”:{“ fields”:postBody}}的方式包装postBody.

这与另一个问题有些混淆,因为bq update会为您完成此包装.

您看到更新失败的原因是因为bigquery服务器根本看不到任何架构,因此认为您正在尝试删除架构.而且patch成功,但什么也不做,因为它根本看不到任何有效字段,因此只执行null补丁操作.

这是向字段添加字段的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"

标签:php,google-bigquery
来源: https://codeday.me/bug/20191012/1897639.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有