Google Bigquery:如何更新分区表的分区到期时间?

时间:2018-04-23 11:38:28

标签: google-bigquery

Bigquery文档说它可以更新分区表的分区时间到期。而我只能为摄取时间分区表做到这一点。我尝试了下面的内容:

  bq query --use_legacy_sql=false ' 
  CREATE TABLE IF NOT EXISTS [DATASET].partitioned_table_ingestion_time ( 
      event_date DATE NOT NULL, 
      event_id INT64) 
  PARTITION BY DATE(_PARTITIONTIME)
  OPTIONS( 
     partition_expiration_days=10, 
     description="table partitioned by ingestion time and with expiry" 
   )' 

更新查询和结果:

  # update expiry to 7 days = 7 * 24 * 60 * 60 = 604800 s
  bq update --time_partitioning_expiration 604800 [PROJECT-ID]:[DATASET].partitioned_table_ingestion_time

  Table 'PROJECT-ID]:[DATASET].partitioned_table_ingestion_time' successfully updated.

现在为分区表:

  bq query --use_legacy_sql=false ' 
  CREATE TABLE IF NOT EXISTS [DATASET].partitioned_table ( 
      event_date DATE NOT NULL, 
      event_id INT64) 
  PARTITION BY event_date
  OPTIONS( 
     partition_expiration_days=10, 
     description="table partitioned by event_date with expiry" 
   )' 

在这种情况下更新失败

  # update expiry to 7 days
  bq update --time_partitioning_expiration 604800 [PROJECT-ID]:[DATASET].partitioned_table 

  BigQuery error in update operation: Cannot change partitioning spec for a partitioned table.

如何在此处更新分区时间到期?

4 个答案:

答案 0 :(得分:4)

请尝试此操作,将分区字段指定为Process p = Runtime.getRuntime().exec(command); 命令的一部分:

bq update

编辑:您现在可以使用ALTER TABLE SET OPTIONS statement来更改分区到期时间。例如:

bq update --time_partitioning_field=event_date \
  --time_partitioning_expiration 604800 [PROJECT-ID]:[DATASET].partitioned_table

答案 1 :(得分:1)

就我而言,当我向命令添加 time_partitioning_type 和 time_partitioning_field 选项时,它已成功更新。

答案 2 :(得分:0)

我们可以尝试通过这种方式进行更新:-

set partition Expiration time on Table

答案 3 :(得分:0)

如果你想彻底删除分区过期,设置NULLpartition_expiration_days选项

ALTER TABLE `project-name`.dataset_name.table_name
SET OPTIONS (partition_expiration_days=NULL);