Google-cloud-python: BigQuery: Cannot update schema for a view

Created on 31 Jan 2019  路  10Comments  路  Source: googleapis/google-cloud-python

BigQuery api doesn't support creating a schema with a view. Eventhough the schema for a view is a relatively new function, I can only set it through the interface. When running:
self.bigquery_client.update_table(table, ["description", "schema", "labels", "view_query", "view_use_legacy_sql"]) or self.bigquery_client.create_table(table)

I get

BadRequest: 400 POST https://www.googleapis.com/bigquery/v2/projects/sp-core-data/datasets/experimental/tables: Schema field shouldn't be used as input with a view

This function should be available now since schemas for views are a functionality of the UI.

question bigquery backend

All 10 comments

@joelostlund I'm afraid there isn't anything in this the Python google-cloud-bigquery library which is generating that error: it is coming from the back-end API.

@tswast Can you please comment?

The error is originating from the BigQuery API backend, but I'd like to confirm the flow of events. You're creating a logical view via the library, or updating an existing view? The goal is to set the description on the projected fields in the schema, or are you trying to amend the projected field list in some other fashion?

Note: created internal issue 123767878 to track this with the BQ backend.

Yeah, sounds like an API issue. Hopefully it would just work when published there.

I believe this should work now. Creating a view will yield the derived schema, and a table update call can amend the schema field descriptions.

Creating a view with a schema still doesn't seem to work though @shollyman. At least in terraform I need a 2-step procedure to add descriptions, and this also prevents marking fields as required.

Creating a view with a schema still doesn't seem to work though @shollyman. At least in terraform I need a 2-step procedure to add descriptions, and this also prevents marking fields as required.

I am also facing this issue. Wondering how you managed to create a view with column descriptions using Terraform?

I am also facing this issue... Did you have any updates?

The following work around was enough for me as mentioned by @shollyman:

from google.cloud import bigquery

client = bigquery.Client()

# Create table
table_id = "your-project.your_dataset.your_table_name"
table = bigquery.Table(table_id)
table.view_query = some_query
table = client.create_table(table) # Make an API request

# Update table
table.schema = some_schema_with_descriptions
table = client.update_table(table, ["schema"])  # Make an API request.

@aleks-djuric, I guess this answers the initial question but not how to create a view with column descriptions using _Terraform_?

Was this page helpful?
0 / 5 - 0 ratings