本頁面中的部分或全部資訊可能不適用於 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'
使用擷取時間分區時,您可以運用這項技巧,將舊資料載入與原始資料建立時間相應的分區。
您也可以使用這項技巧調整時區。根據預設,擷取時間分區是以世界標準時間為準。如要讓分區時間符合特定時區,可以使用分區修飾符來抵銷世界標準時間的擷取時間。舉例來說,如果您位於太平洋標準時間 (PST) 時區,可利用相應的明確分區修飾符 $2016050123
,將太平洋標準時間 2016 年 5 月 1 日 23:30 產生的資料載入該日期的分區。如果沒有使用這個明確的裝飾器,系統會改為載入 $2016050207
(世界標準時間 5 月 2 日 07:00)。
如果是時間單位資料欄和整數範圍分區資料表,修飾符中指定的分區 ID 必須與寫入的資料相符。舉例來說,如果資料表是依據 DATE
資料欄分區,裝飾符必須與該資料欄中的值相符。否則會發生錯誤。不過,如果您事先知道資料位於單一分區,指定分區修飾符可以提升寫入效能。
上述範例會將資料附加至分區。如要改為覆寫分割區中的資料,請務必在每個指令中加入不同旗標,也就是 bq load --replace=true ...
和 bq query --append_table=false ...
。
如要進一步瞭解這些指令中的標記,請參閱 bq load
和 bq query
。
如要進一步瞭解如何載入資料,請參閱將資料載入 BigQuery 的簡介一文。
以串流方式將資料傳入分區資料表
如要瞭解如何使用 BigQuery Storage Write API,以串流方式將資料傳入分區資料表,請參閱「以串流方式將資料傳入分區資料表」一文。
後續步驟
如要進一步瞭解分區資料表的使用,請參閱:
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-08 (世界標準時間)。
[[["容易理解","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"]],["上次更新時間:2025-08-08 (世界標準時間)。"],[[["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."]]],[]]