How do I use BigQuery patch?

后端 未结 1 1525
抹茶落季
抹茶落季 2021-01-12 23:20

In the BigQuery API documentation there is a method called patch. I am hoping that I can use it to alter the schema of an existing table. Unfortunately it is not supported

相关标签:
1条回答
  • 2021-01-13 00:08

    TLDR: You need to supply the complete schema in the body of the patch request, not just the fields you're trying to add. The backend error is likely caused by the empty fields in that array.


    BigQuery's API allows tables (and other resources) to be updated in two ways: update and patch.

    The update method replaces the table resource with the new resource that you supply. This method is useful in cases where you want to take an existing table resource, modify it, and then post that modified table resource back to BigQuery in its entirety. (Note, however, that some fields of the object, such as creationTime, are considered immutable, so the new values supplied for these fields will be ignored.)

    The patch method only replaces the fields that you include in the request, and leaves the rest of the resource unchanged. This method is useful if you want to make an isolated change to one field without worrying about the rest. This algorithm is applied recursively to any nested objects, but not to nested arrays. In other words, the patch resource that you send with the request is merged recursively with the existing resource until an array or scalar value is encountered, at which point the array or value in the patch object replaces the one in the existing resource.

    Since the schema you're trying to update contains an array of fields, and since the patch method updates arrays wholesale, your patch object needs to contain the complete array of fields that you want in the resulting schema. (You can't add a field by specifying a one-field array in the patch object.)

    Note that the table ID is given in the request URL, so it doesn't need to be included in the object itself.

    Finally, the backend error is a problem on our end, likely a result of the two empty schema fields in your request. We'll dig further and hopefully improve the error message for the future.

    0 讨论(0)
提交回复
热议问题