Патч / Обновление таблицы BigQuery Google не работает

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 , и мы не можем добавить дополнительные столбцы. Обновление возвращает: Provided Schema does not match . Патч возвращает значение.

В postBody мы пробовали разные синтаксисы, и никто из них не работает. [etag] => (string) "wRHWmN_1J7FEq2j8vIkltiyoyRw/GVGxfUY15UK1iZLhzZzfWOf-1Ow"

Мы пробовали следовать этому Q & A Bigquery добавить столбцы в схему таблицы

Мы видим, что поле 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... 

update2 с помощью PATCH

Это когда у меня есть tableResource и схема, и с помощью 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"},{"... 

update3 с использованием PUT

При использовании узла обновления я все равно получаю, что 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"},{"... 

Solutions Collecting From Web of "Патч / Обновление таблицы BigQuery Google не работает"

При вызове патча или обновления вам необходимо предоставить что-то похожее на таблицу. В приведенном выше примере, похоже, что вы не передаете ресурс таблицы, а только поля внутри ресурса таблицы. Возможно, вам придется обернуть ваш postBody в нечто вроде {"schema": {"fields": postBody } }

Это немного путано с другим вопросом, потому что обновление bq делает эту упаковку для вас.

Причина, по которой вы обнаруживаете ошибку обновления, заключается в том, что сервер bigquery вообще не видит никакой схемы, поэтому он думает, что вы пытаетесь удалить схему. И патч преуспевает, но ничего не делает, потому что он вообще не видит никаких допустимых полей, поэтому он просто выполняет операцию с нулевым патчем.

Ниже приведен пример сеанса curl, который добавляет поля в схему. Относительно легко адаптироваться к php. Здесь используется 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"