goccy / bigquery-emulator

BigQuery emulator server implemented in Go
MIT License
844 stars 108 forks source link

Response from table update is incompatible with Google's Python SDK #293

Open mastizada opened 7 months ago

mastizada commented 7 months ago

What happened?

When table schema is updated, it calls BigQuery.updateTable with PATCH method. With bigquery-emulator, it is returning the updated schema, however, google-cloud-bigquery plugin expects tableReference with tableId in the response. Link to the plugin function.

What did you expect to happen?

To have [tableReference][tableId] in the response.

How can we reproduce it (as minimally and precisely as possible)?

Install the python plugin: $ pip install google-cloud-bigquery (tested on latest version, 3.20.1, and old version 2.34.3).

Execute the following code:

from google.auth.credentials import AnonymousCredentials
from google.cloud import bigquery

client = bigquery.Client(client_options={"api_endpoint": "http://0.0.0.0:9050"}, credentials=AnonymousCredentials())

# change project id, dataset name and table name
table_ref = ".".join([GCP_PROJECT_ID, DATASET_NAME, TABLE_NAME])
table = client.get_table(table_ref)

# slightly modify `table.schema`
table = client.update_table(table, ["schema"])

It will give the following error: KeyError: 'Resource lacks required identity information:["tableReference"]["tableId"]'

Anything else we need to know?

No response

ohaibbq commented 7 months ago

It seems to me that the PATCH /projects/{project]/datasets/{dataset}/tables/{table} endpoint has numerous problems.

We currently decode the request body into a bigquery.Table. For example, if we are updating the description, we'd end up with a bigquery.Table with only the description set.

The newTable metadata is then passed along to metadata.Table.Update, but is unused, resulting in a no-op.

The response for the request handler only contains the contents of r.newTable, so in this case it'd be only be the description, no other fields.

As an aside, its worth noting that the emulator does not currently support updating a table's schema.