在BigQuery Python API中设置集群列 [英] Setting clustering column in BigQuery python api
问题描述
我正在尝试在BigQuery中创建集群表.
I'm trying to create a clustered table in BigQuery.
当我在用户界面中对其进行测试时,它可以完美运行:
When I test it in the UI, it works perfectly:
CREATE OR REPLACE TABLE `project_id_xyz.temp.clustering`
PARTITION BY date
CLUSTER BY cluster_col AS
SELECT CURRENT_DATE() as date, 1 as cluster_col
但是,当我在python(3.7.1)中通过google-bigquery == 1.9.0尝试相同操作时,该表已创建并已分区但未群集.在用户界面的详细信息"标签中可以看到.
However when I try the same via google-bigquery==1.9.0 in python (3.7.1), the table is created and partitioned but not clustered. As seen in the "details" tab in the UI.
这是我用来创建表格的代码段.
Here is the snippet I use to create the table.
dataset = client.dataset("temp")
table = dataset.table("clustering_test")
job_config = bigquery.QueryJobConfig()
job_config.destination = table
job_config.write_disposition = "WRITE_TRUNCATE"
time_partitioning = TimePartitioning()
time_partitioning.field = "date"
job_config.time_partitioning = time_partitioning
job_config.clustering_fields = ["cluster_col"]
sql = """
SELECT CURRENT_DATE() as date, 1 as cluster_col
"""
query_job = client.query(
sql,
location='US',
job_config=job_config)
query_job.result()
代码看起来非常简单,也不会引发任何异常.
Code seems very straightforward and also doesn't throw any exceptions.
有什么明显的地方我做错了吗?
Is there anything obvious that I'm doing wrong?
推荐答案
我运行了您的python代码,并且可以通过集群设置确认它可以正常工作.
I run your python code and I can confirm it's working as expected with the cluster settings.
使用Python 3.6.7解决问题的方法是创建一个干净的版本并再次运行代码
The solution for your problem using Python 3.6.7 is to create a clean version and run your code again
这篇关于在BigQuery Python API中设置集群列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!