google-bigquery - BigQuery:如何使用 bigquery.Client().copy_table 方法覆盖表
问题描述
这是我用作https://cloud.google.com/bigquery/docs/managing-tables#bigquery-copy-table-python参考的代码:
source_dataset = client.dataset('samples', project='bigquery-public-data')
source_table_ref = source_dataset.table('shakespeare')
# dataset_id = 'my_dataset'
dest_table_ref = client.dataset(dataset_id).table('destination_table')
job = client.copy_table(
source_table_ref,
dest_table_ref,
# Location must match that of the source and destination tables.
location='US') # API request
job.result() # Waits for job to complete.
在我的情况下,目标表存在,我收到此错误:
Already Exists
如何用这个 copy_table 方法覆盖?在 bq 命令行中,我可以使用 -f 选项。所以我正在寻找相同的标志。
解决方案
您需要将作业配置传递给请求,如下所示:
job_config = bigquery.CopyJobConfig()
job_config.write_disposition = "WRITE_TRUNCATE"
job = client.copy_table(
source_table_ref,
dest_table_ref,
location='US',
job_config=job_config) # API request
推荐阅读
- kotlin - 使用 ktor 和 kotlin 对 kafka 消费者进行抽象
- monaco-editor - 如何从摩纳哥编辑器中获取诸如未定义变量之类的错误?
- ignite - 为什么 Apache Ignite Cache.replace-KVV api 调用执行缓慢?
- amazon-web-services - 由 AWS EKS 管理的 Kubernetes 工作程序节点的固定 IP 地址
- animation - Flutter 中的文本是否有水平淡入淡出功能?
- html - 位置:如果父级有溢出,则粘性不起作用:自动样式
- eclipse - Eclipse 调试器无法启动
- php - 中间件中的 Laravel 会话并不总是设置
- angular - How to order mat-select alphabetically when options have conditional names
- python - Tkinter & Turtle Etch-a-Sketch