【发布时间】:2022-02-22 17:54:40
【问题描述】:
我在 BigQuery 的分区表中创建和插入数据时遇到问题。
我的脚本每天都会下载过去 7 天的一些数据。我将它们保存在数据框中,然后将它们加载到 Big Query 分区表中。
昨天脚本将前 7 天的数据保存到 BigQuery 表中(2022-02-14 和 2022-02-20 之间)。 今天它保存了 7 天前(2022-02-15 和 2022-02-21 之间)的数据,但不再有昨天保存的前 7 天的数据(例如,没有更多数据2022-02-14 那天)。
这是我的代码:
schema = [
bigquery.SchemaField("Date", "DATE", "REQUIRED"),
bigquery.SchemaField("Advertiser", "STRING", "REQUIRED"),
bigquery.SchemaField("AdvertiserId", "INTEGER", "REQUIRED"),
bigquery.SchemaField("Campaign", "STRING", "REQUIRED"),
bigquery.SchemaField("CampaignId", "INTEGER", "REQUIRED")
]
job_config = bigquery.LoadJobConfig(
schema=schema,
write_disposition="WRITE_TRUNCATE",
time_partitioning=bigquery.TimePartitioning(
type_=bigquery.TimePartitioningType.DAY,
field="Date", # Name of the column to use for partitioning.
),
)
job = client.load_table_from_dataframe(df, MY_PROJECT_ID.MY_DATASET.MY_TABLE_NAME), job_config=job_config) # Make an API request.
job.result() # Wait for the job to complete.
为什么分区不工作? 谢谢!
【问题讨论】:
标签: python google-cloud-platform google-bigquery