我正在尝试将 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 更改?因为这个脚本在一个月前工作。
请帮忙。