【问题标题】:Loading data to “Partitioned Tables” with Write_Truncate using BQ API使用 BQ API 使用 Write_Truncate 将数据加载到“分区表”
【发布时间】:2016-06-06 10:59:40
【问题描述】:

可以使用 write_truncate 将数据加载到特定分区吗? 我的用例将是一个批量加载过程,它覆盖特定分区,同时保持表的其余部分完好无损。 此参考仅提及命令行工具: https://cloud.google.com/bigquery/docs/creating-partitioned-tables#restating_data_in_a_partition

【问题讨论】:

    标签: google-bigquery


    【解决方案1】:

    是的。每个分区的行为就像它是单独的表一样,因此您可以将特定分区作为目标表并进行覆盖。从 UI 和 API 工作。表格的其余部分没有变化。
    甚至长期存储定价也适用于分区表

    【讨论】:

    • 这怎么可能?您能否举一个示例,我们可以截断并加载到 BigQuery 表中的特定分区。
    【解决方案2】:

    如果您想使用 BQ API 写入特定分区,请像写入表一样继续操作,但在表 id 中包含分区装饰器。

    如果您有一个date partitionedtransactions,并且您想将数据加载到与2021-10-11 对应的分区,请将transactions$20211011 传递给API。

    如果您有一个带有每小时分区的ingestion-time partitionedtransactions,并且您希望将数据加载到与2021-05-07 17:00:00 对应的分区,请将transactions$2021050717 传递给API。

    示例:如果您正在使用 python 的 API 将 DataFrame 加载到 BQ 中并且想要覆盖分区,您可以这样做:

    from google.cloud import bigquery
    client = bigquery.Client(project='your_project')
    
    job_config = bigquery.LoadJobConfig(
        write_disposition="WRITE_TRUNCATE", 
    )
    
    # Include target partition in the table id:
    table_id = "your_project.your_dataset.your_table$20211021" 
    job = client.load_table_from_dataframe(df, table_id, job_config=job_config) # Make an API request
    job.result() # Wait for job to finish
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-03
      • 2019-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多