无法在BigQuery中使用DML语句的作业中设置目标表 [英] Cannot set destination table in jobs with DML statements in BigQuery
问题描述
我正在研究使用bigquery.Client.query执行BigQuery sql命令的Python代码.我收到无法在具有DML语句的作业中设置目标表.
I am working on Python code to execute BigQuery sql command using bigquery.Client.query. I am getting Cannot set destination table in jobs with DML statements exception.
下面是我正在使用的Python代码
Below is the Python code I am using
if query_file_name:
with open(query_file_name, mode="r") as query_file:
query = query_file.read()
job_config = bigquery.QueryJobConfig()
job_config.use_legacy_sql = use_legacy_sql
if destination:
if destination.partitioned_field:
job_config.time_partitioning = TimePartitioning(type_=TimePartitioningType.DAY,
field=destination.partitioned_field)
google_bq_table = self.fetch_table_reference(destination)
job_config.destination = google_bq_table
job_config.write_disposition = WriteDisposition.WRITE_APPEND
query_job = self.google_client.query(query, job_config=job_config) # API request - starts the query asynchronously
我有如下BigQuery sql中的query_file
I have query_file as in below BigQuery sql
INSERT mydataset.target_table
(col1, col2, col3, created_date)
WITH T AS (SELECT col1, col2, col3, CURRENT_DATE() as created_date
from mydataset.temp_table
)
SELECT col1, col2, col3, created_date FROM T
提前感谢您的帮助
谢谢
Raghunath.
Raghunath.
推荐答案
无法在具有DML语句的作业中设置目标表
Cannot set destination table in jobs with DML statements
作为BigQuery错误消息中的统计信息,您在运行插入命令时无法在python代码目标对象中进行设置.
As stat in BigQuery error message, you can't set in your python code destination object when running an insert command.
删除此行
if destination:
if destination.partitioned_field:
job_config.time_partitioning = TimePartitioning(type_=TimePartitioningType.DAY,
field=destination.partitioned_field)
google_bq_table = self.fetch_table_reference(destination)
job_config.destination = google_bq_table
通过您的代码可以解决您的问题
from your code will solve your problem
这篇关于无法在BigQuery中使用DML语句的作业中设置目标表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!