BigQuery table partitioning for Daton pipelines
BigQuery table partitioning for Daton pipelines
Purpose: Step-by-step workflow to partition Daton-loaded tables safely (pause → rebuild → swap → resume), plus field suggestions and operational notes.
1. BigQuery behavior and constraints
Partitioning is defined when the table is created. Time-unit and other column-based partitioned tables use
CREATE TABLE with a PARTITION BY clause; see Google’s guide on creating partitioned tables.
You cannot change the partitioning “kind” or expression in place with
CREATE OR REPLACE. The same DDL page states (under Limitations): “It is not possible to use the OR REPLACE modifier to replace a table with a different kind of partitioning. Instead, DROP the table, and then use a CREATE TABLE ... AS SELECT ... statement to recreate it.” That is the supported pattern when you need a different partition layout—including migrating from an unpartitioned table to a time-unit column–partitioned table.
What you can change later on an already-partitioned table (without redefining
PARTITION BY) includes options such as partition expiration and require partition filter, via ALTER TABLE ... SET OPTIONS—see Managing partitioned tables (partition expiration and partition filter sections).
Practical takeaway for Daton tables: Build a new partitioned table (for example
CREATE TABLE ... PARTITION BY ... AS SELECT * FROM ...), validate, then swap names or repoint the pipeline—consistent with Google’s stated DROP + CREATE TABLE ... AS SELECT ... approach when partitioning must change.2. Recommended workflow (pause → partition → resume)
Steps to be followed in brief are -
- Pick partition column
- Pause Daton for that source.
-
CREATE TABLE ... PARTITION BY ... AS SELECTinto a new table; validate counts and sample data. - Swap to the original table name (or update Daton destination per product capability).
- Resume Daton and verify the next sync.
- Update downstream queries/dashboards to always filter on the partition column where possible.
Follow the below section for detailed steps and guide:
Step 1 — Plan
- Identify the table(s) and the partition column (see Section 4).
- Confirm the column type is compatible with BigQuery partitioning:
- Prefer
DATEforPARTITION BY DATE(col). -
TIMESTAMP/DATETIMEare supported with the appropriatePARTITION BYexpression.
- Estimate size and downtime: large tables take longer to copy; Daton must stay paused until the swap is complete.
Step 2 — Pause the Daton source (connector)
- In Daton, pause the connector (or the specific table) that writes to the target table(s).
- Wait for in-flight loads to finish so you do not have partial writes during the migration.
Pausing prevents Daton from writing while you replace or rename tables, which avoids schema drift, duplicate loads, or failed jobs mid-migration.
Step 3 — Create a partitioned copy of the table
Run a DDL job in BigQuery (Console, scheduled query, or API). Pattern:
Option 1 — Same dataset, temporary name then swap
-- 1) Create partitioned clone (example: daily partition on date_start)CREATE TABLE `project.dataset.table_name__partitioned` PARTITION BY date_start ASSELECT *FROM `project.dataset.table_name`;
Adjust:
-
PARTITION BY date_startifdate_startis alreadyDATE. - If
date_startisSTRING, cast in the partition expression, e.g.PARTITION BY DATE(PARSE_DATE('%Y-%m-%d', date_start))— only if the string is consistently parseable; fix bad values first or exclude them in a controlledSELECT.
Option 2 — Partition on ingestion-time (only if you do not have a reliable business date column)
PARTITION BY DATE(_PARTITIONTIME)
Ingestion-time partitioning is rarely ideal for Daton marketing tables where
date_start (or similar) matches how users query.Step 4 — Validate the new table
- Row count (should match source unless you filtered):
SELECT COUNT(*) FROM `project.dataset.table_name`; SELECT COUNT(*) FROM `project.dataset.table_name__partitioned`;
- Spot-check a few partitions and min/max dates:
SELECT date_start, COUNT(*) FROM `project.dataset.table_name__partitioned` GROUP BY 1ORDER BY 1 DESC LIMIT 20;
- Run a test query with a
WHERE date_start BETWEEN ...and confirm bytes processed drops versus the old table (query info in BigQuery UI).
Step 5 — Swap names (replace the table Daton expects)
Use
ALTER TABLE ... RENAME TO (no second full copy)BigQuery supports renaming a table in place with DDL (Rename a table). The new table name is unqualified and stays in the same dataset as the original. Google documents that this operation recreates the table while preserving the original creation time (watch dataset-level table expiration if enabled).
Limitations include: no external tables, no concurrent DML on the table during rename.
Typical swap after
table_name__partitioned is validated:ALTER TABLE `project.dataset.table_name` RENAME TO table_name__old; ALTER TABLE `project.dataset.table_name__partitioned` RENAME TO table_name; -- After Daton resumes successfully and you no longer need the backup:-- DROP TABLE `project.dataset.table_name__old`;
You do not need to drop the old table first if you do the two-step rename above. The first rename frees
table_name, then the second rename takes that name.Step 6 — Resume Daton
- Resume the connector.
- Watch the next sync for errors (schema mismatch, partition column nulls, etc.).
- Re-run the bytes processed test query after new data lands.
3. Best practices
4. Choosing a partition column
1. Which date column do analysts put in the
WHERE clause when filtering by date range? That column is almost always the right choice. Partitioning only saves bytes when queries filter on the partition column — so pick the one that is already being used to scope time.
2. Does that column have a clean
DATE or TIMESTAMP type with very few NULLs? If yes, you are ready to go. If it is stored as a STRING, check whether the values are consistently formatted (e.g. '2024-01-15') — a reliable cast like DATE(PARSE_DATE('%Y-%m-%d', col)) still works. Rows with a NULL partition value land in a separate __NULL__ partition and do not benefit from pruning.
3. If more than one column qualifies, which one represents when the event happened rather than when it loaded? Prefer the business event date (e.g. the ad reporting date, the order placement date) over the pipeline ingestion timestamp (
_daton_batch_runtime). Analysts query by event date, not load time.Shortcut: Open the table in BigQuery Console, look at the schema, and ask ”what would I put in a
WHEREclause if I only wanted last month's data?” — that column is your partition key.
Quick-pick by platform
Always confirm the exact column name and type in your dataset before running the DDL — connector versions and client configurations can differ.