[英]Google BigQuery: creating a view via Python google-cloud-bigquery version 0.27.0 vs. 0.28.0
所有,
我在用两周前发布的bq库的0.28版本在python中创建Google BigQuery视图时遇到了麻烦。 我很确定问题就在我这边,我缺少了一些东西,但是我找不到问题。
请保持谦虚,我不会在网上问很多问题,但我很沮丧。 我也不是完全不称职,以下是一些详细信息:
我已经审查了https://cloud.google.com/bigquery/docs/python-client-migration
我认为问题出在“修复” https://github.com/GoogleCloudPlatform/google-cloud-python/pull/4038 BigQuery上:用client.create_table()替换table.create()#4038
问题? 下面第二个块中的代码创建一个TABLE,没有模式,也没有记录。 它显然应该改为创建VIEW,对吗?
须藤点安装-IV google-cloud-bigquery == 0.27.0
from google.cloud import bigquery
project=None
dataset_name = 'my_dataset_id'
view_name = 'vw_dummy_data20'
sqlQuery = 'select record_id as id, UPPER(first_name) as first_name, UPPER(last_name) as last_name from [my_project_code:my_dataset_id.dummy_data13]'
bigquery_client = bigquery.Client(project=project)
dataset = bigquery_client.dataset(dataset_name)
table = dataset.table(view_name)
table.view_query = sqlQuery
table.create()
上面的作品很好,创建的视图很棒!
在下面,仅创建了一个表,没有行,没有架构,!
sudo pip卸载google-cloud-bigquery
须藤点安装-IV google-cloud-bigquery == 0.28.0
from google.cloud import bigquery
project=None
dataset_name = 'my_dataset_id'
view_name = 'vw_dummy_data21'
sqlQuery = 'select record_id as id, UPPER(first_name) as first_name, UPPER(last_name) as last_name from [my_project_code:my_dataset_id.dummy_data13]'
bigquery_client = bigquery.Client(project=project)
dataset_ref = bigquery_client.dataset(dataset_name)
table_ref = dataset_ref.table(view_name)
table_ref.view_query = sqlQuery
table_ref.view_use_legacy_sql = True
table = bigquery.Table(table_ref)
bigquery_client.create_table(table)
其他连结:
任何有用的想法将不胜感激。
谢谢和最诚挚的问候...丰富
你好亲密!
问题在于线
table_ref.view_query = sqlQuery
table_ref.view_use_legacy_sql = True
TableReference
类不包含这些属性。 相反,您必须将它们填充在Table
类上,如
table = bigquery.Table(table_ref)
table.view_query = sqlQuery
table.view_use_legacy_sql = True
bigquery_client.create_table(table)
蒂姆的答案很完美,非常感谢。
这是最终代码:
from google.cloud import bigquery
bigquery_client = bigquery.Client(project=project)
dataset_ref = bigquery_client.dataset(dataset_name)
table_ref = dataset_ref.table(view_name)
table = bigquery.Table(table_ref)
table.view_query = sqlQuery
table.view_use_legacy_sql = True
bigquery_client.create_table(table)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.