python-3.x - 将 SELECT 语句结果导出到 BigQuery 时,仅创建空表
问题描述
我正在尝试将 select 语句结果导出到另一个表作为永久存储。但是,无论何时创建新表,它都是无模式的。当我尝试查询该结果表时,会显示错误:
表 project-id.dataset_name.temp_table 没有架构。
这是我将结果从 SELECT 语句导出到临时选项卡的代码
def query_to_table():
service_account_info = {} # account info
credentials = Credentials.from_service_account_info(
service_account_info)
client = bigquery.Client(
project=service_account_info.get("project_id"),
credentials=credentials)
query = """
SELECT
a,
b
FROM `project.dataset.table`
WHERE a NOT IN ('error', 'warning')
"""
destination_dataset = client.dataset("abc_123") #this is another dataset
destination_table = destination_dataset.table("temp_table") # destination table
try:
client.get_table(destination_table)
client.delete_table(destination_table)
except Exception as e:
# Some logging
pass
client.create_table(Table(destination_table))
# Execute the job and save to table
job_config = bigquery.QueryJobConfig()
job_config.allow_large_results = True
job_config.use_legacy_sql = False
job_config.destination = destination_table
job_config.dry_run = True
query_job = client.query(query, job_config=job_config)
# Wait till the job done
while not query_job.done():
time.sleep(1)
logging.info(f"Processed {query_job.total_bytes_processed} bytes.")
return destination_table
错误在哪里?Google Cloud 方面是否有任何 API 更改?因为这个脚本在一个月前工作。
请帮忙。
解决方案
该死!我只是想通了,那是因为我dry_run
将True
.
根据这个:https : //stackoverflow.com/a/28355802/4494547,如果dry_run设置为True,它只是评估查询而不实际运行作业。
花了我 5 个小时搞定我的脑袋。:(
推荐阅读
- python - 使用海龟图形的对象实现生成图片
- hadoop - 删除列重复字符串值并提取 coulm 值的最大字符串值
- python - 一种在连续数组上维护索引指针的方法
- mysql - 如何在 NodeJS 中的相同代码中返回承诺以及关闭 mysql 连接
- tsql - 在列中显示 texte 或 unicode
- javascript - 从 javascript Appication 更新位于 VSTS 存储库的文件
- java - @ElementCollection 不会分离
- php - Opencart 短 seo 网址
- c# - 检查收到的文档是自定义管道组件中的 XML 还是 Edifact
- f# - 在有区别的联合上实现 F# 比较