BigQuery - 从 Google 云存储传输自动化 - 覆盖 table

BigQuery - Transfers automation from Google Cloud Storage - Overwrite table

案例如下:

事实是,即使我们已经:

  1. 在 BigQuery 中使用 "Overwrite table" 写入首选项声明 tables
  2. 通过 UI(BigQuery > 传输)配置每日传输,在文件上传到 Google 云一小时后自动从 Google 云上传 CSV,as stated by the limitations.

自动 transfer/load 默认情况下在 "WRITE_APPEND" 中,因此 table 在 BigQuery 中被附加而不是被覆盖。

因此问题:How/where 我们可以更改

configuration.load.writeDisposition = WRITE_TRUNCATE

如上所述 here 以便在自动加载 CSV 时覆盖 table?

我想这就是我们所缺少的。

干杯。

1) 一种方法是在 运行 导入数据的查询之前使用 DDL CREATE and REPLACE 您的 table。

这是一个如何创建 table

的示例
#standardSQL
 CREATE TABLE mydataset.top_words
 OPTIONS(
   description="Top ten words per Shakespeare corpus"
 ) AS
 SELECT
   corpus,
   ARRAY_AGG(STRUCT(word, word_count) ORDER BY word_count DESC LIMIT 10) AS top_words
 FROM bigquery-public-data.samples.shakespeare
 GROUP BY corpus;

现在它已创建,您可以导入数据了。

2) 另一种方法是使用 BigQuery 计划查询

3) 如果你写Python你可以找到更好的解决方案

None 以上对我们有用,所以我发布这个以防有人遇到同样的问题。

我们计划在自动导入过程开始之前删除 table 内容的查询:

DELETE FROM project.tableName WHERE true

然后,新数据将被导入到空table,因此默认"WRITE_APPEND"不会影响我们。