本页面上的部分或全部信息可能不适用于 Trusted Cloud by S3NS。
将数据加载到分区表中
本文档介绍了如何将数据加载到分区表中。
将数据写入特定分区
您可以使用带有分区修饰器的 bq load
命令将数据加载到特定分区。以下示例会将数据附加到现有表的 20160501
(2016 年 5 月 1 日)分区中(假设该表已按日期分区):
bq load --source_format=CSV 'my_dataset.my_table$20160501' data.csv
您还可以将查询结果写入特定分区:
bq query \
--use_legacy_sql=false \
--destination_table='my_table$20160501' \
--append_table=true \
'SELECT * FROM my_dataset.another_table'
通过注入时间分区,您可以使用此方法将较旧的数据加载到与最初创建数据的时间对应的分区中。
您也可以使用此方法来根据时区进行调整。默认情况下,注入时间分区基于世界协调时间 (UTC)。如果您希望分区时间与特定时区匹配,可以使用分区修饰器来抵消 UTC 注入时间。例如,如果您使用的是太平洋标准时间 (PST),则可以使用相应的显式分区修饰器 $2016050123
将太平洋标准时间 2016 年 5 月 1 日 23:30 生成的数据加载到该日期的分区中。如果您未使用此显式修饰器,则它会加载到 $2016050207
(世界协调时间 (UTC) 5 月 2 日 07:00)。
对于时间单位列和整数范围分区表,修饰器中指定的分区 ID 必须与写入的数据匹配。例如,如果表基于 DATE
列进行分区,则修饰器必须与该列中的值匹配。否则将发生错误。但是,如果您事先知道数据位于单个分区中,指定分区修饰器可以提高写入性能。
上述示例将数据附加到某个分区。如需改为覆盖分区中的数据,您必须为每个命令添加不同的标志,即 bq load --replace=true ...
和 bq query --append_table=false ...
。如需详细了解这些命令中的标志,请参阅 bq load
和 bq query
。
如需详细了解如何加载数据,请参阅将数据加载到 BigQuery 简介。
将数据流式传输到分区表中
如需了解如何使用 BigQuery Storage Write API 将数据流式传输到分区表,请参阅时间单位列分区。
后续步骤
如需详细了解分区表的操作,请参阅:
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-05。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-05。"],[[["Data can be loaded into a specific partition of a table using the `bq load` command with a partition decorator, such as `$20160501` for the May 1, 2016 partition."],["Query results can be written to a specific partition by using the `bq query` command and specifying the destination table with a partition decorator, along with appropriate flags."],["Partition decorators can be used with ingestion-time partitioning to load older data into the correct partition or to adjust for time zone differences, by loading the data into a partition reflecting the correct time."],["For time-unit column and integer-range partitioned tables, the partition ID specified in the decorator must align with the data being written to avoid errors, although it can improve write performance."],["Data can be appended or overwritten in a partition by adjusting `bq load` or `bq query` flags."]]],[]]