Skip to contentManaged Kafka is live: Apache Kafka on AWS for half the cost of MSK

BigQuery

Enable BigQuery partitioning

Partition your BigQuery destination tables so each Artie merge reads only the partitions its rows fall in.

How you enable partitioning depends on whether the table already exists in BigQuery:

  • New tables: Artie creates the table partitioned by hour, day, month or year from the column and granularity you select.
  • Existing tables: BigQuery can’t partition a table after it’s created, so you recreate the table, then update its settings in Artie.

The examples in this guide use this source table in PostgreSQL:

SQL
CREATE TABLE events (
    event_id SERIAL PRIMARY KEY,
    event_name VARCHAR(255) NOT NULL,
    description TEXT,
    created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

Choose a partition column

Pick a TIMESTAMP, DATETIME or DATE column that your queries filter on, such as created_at or event_date.

Pick a column whose value stays fixed after a row is inserted. Artie filters each merge to the partitions of the incoming rows’ values. A row whose value moves to a different partition doesn’t match its old copy, so the merge inserts a duplicate. For that reason, avoid a column like updated_at.

If any row in a batch has no value in the partition column, Artie merges that batch without the partition filter.

Choose a partition granularity

Pick how much time each partition covers. Artie defaults to Daily.

GranularityUse it whenColumn types
HourlyHigh-volume tables that only keep a few months of dataTIMESTAMP, DATETIME
DailyMost change data capture (CDC) workloadsTIMESTAMP, DATETIME, DATE
MonthlyTables with many years of history, or low volume per dayTIMESTAMP, DATETIME, DATE
YearlyVery long history with low volume per monthTIMESTAMP, DATETIME, DATE

BigQuery limits a single job to modifying 4,000 partitions, and a table to 10,000 partitions. A backfill merge can touch rows from across the whole table. Pick a granularity where your partition column spans fewer than 4,000 partitions: about 5 months of hours, or about 10 years of days.

A yearly filter still reads all of the current year, so on this table of about 100,000 rows a day it reads more than no filter. Yearly suits long history with low monthly volume. Measured for the blog post BigQuery MERGE Partition Pruning: Why CDC Merges Need a Partition Filter.

Partition a new table

Artie adds partitioning only when it creates the table, so set the partition column before the table exists in BigQuery.

In a new pipeline

The setup flow asks for tables before the destination. Merge predicate appears in a table’s settings only after the pipeline has a BigQuery destination.

  1. Connect BigQuery

    In the pipeline setup flow, complete the Destination steps with BigQuery as the destination.

  2. Open the table's settings

    In the list of setup steps, select Choose tables, then select the events row.

    The table’s columns and settings open. If Replicate this table is off, turn it on.

  3. Select the partition column

    Expand Advanced options, then select created_at in Merge predicate.

    Partition granularity appears, set to Daily.

  4. Select the granularity

    Select a Partition granularity, then select Done.

    Hourly isn’t listed for a DATE column.

  5. Deploy

    On Review and deploy, select Validate and deploy, then select Deploy.

    When Artie creates the events table, it adds the partitioning clause.

  6. Verify

    Follow Verify partitioning once the table has data.

In a deployed pipeline

To partition a table that you add to a deployed pipeline, edit the pipeline before Artie creates the table.

  1. Open the table's advanced settings

    On the pipeline page, select Edit pipeline, then the Tables tab. On the events row, select Advanced settings.

    Advanced settings appears only on a replicated row. If the events row isn’t replicated, turn on replication for it first.

  2. Select the partition column

    Under Optimizations, turn on Use a merge predicate, then select created_at in Column name.

    Partition granularity appears, set to Daily.

  3. Select the granularity

    Select a Partition granularity, then select Close.

    Hourly isn’t listed for a DATE column.

  4. Deploy

    Select Save changes, then Deploy. In Validate and deploy, select Deploy.

    When Artie creates the events table, it adds the partitioning clause.

  5. Verify

    Follow Verify partitioning once the table has data.

See Use a merge predicate for more on this table setting.

Partitioning clauses

Artie adds one of these clauses when it creates a table partitioned on a BigQuery TIMESTAMP column, like created_at in the example:

GranularityPartitioning clause
HourlyPARTITION BY TIMESTAMP_TRUNC(created_at, HOUR)
DailyPARTITION BY DATE(created_at)
MonthlyPARTITION BY TIMESTAMP_TRUNC(created_at, MONTH)
YearlyPARTITION BY TIMESTAMP_TRUNC(created_at, YEAR)

A DATETIME column uses DATETIME_TRUNC in place of TIMESTAMP_TRUNC. A PostgreSQL TIMESTAMP column without a time zone arrives in BigQuery as DATETIME, unless Force UTC timezone is on in the destination’s advanced settings. A DATE column is partitioned on the column itself for daily partitions, and uses DATE_TRUNC for monthly and yearly partitions.

Artie also filters each merge on the partition column, so BigQuery prunes partitions during merges.

Errors and limits

If Artie can’t partition the table, it stops with one of these errors instead of creating an unpartitioned table:

ErrorCause
partition column "created_at" must be a date or timestamp to partition the table, got: "string"The column has another type, or it’s hashed or encrypted, which makes it a string.
partition column "created_at" is a date, so the table cannot be partitioned by hourHourly is set on a DATE column.
partition column "created_at" is not one of the columns of the table being created, or its type is not known yetThe column isn’t in the table Artie is creating, or Artie doesn’t know its type yet.

These limits also apply:

  • Time partitions only. For integer range partitioning, create the partitioned table in BigQuery first, then select the integer column as the merge predicate.
  • No granularity for integers. Partition granularity appears only for a date or timestamp column.
  • Fixed after creation. Changing the granularity doesn’t change an existing table. To switch, recreate the table.
  • 4,000 partitions per job. If your partition column spans more, pick a coarser granularity.

Partition an existing table

If the table exists in BigQuery and isn’t partitioned, recreate it as a partitioned table while your pipeline is paused.

You need permission to run DDL statements (CREATE TABLE, DROP TABLE, ALTER TABLE) in your BigQuery dataset.

  1. Pause delivery

    On the pipeline page, select Pause pipeline…, keep Pause delivery only selected, then select Pause delivery.

    Artie stops writing to BigQuery and keeps capturing source changes for up to 14 days. Nothing is merged while you restructure the table.

  2. Create a partitioned copy in BigQuery

    In the BigQuery console, run this statement to create a partitioned copy of the table:

    SQL
    CREATE TABLE artie.events_copy
      PARTITION BY DATE(created_at)
      AS SELECT * FROM artie.events;

    For another granularity, swap in its partitioning clause, for example PARTITION BY TIMESTAMP_TRUNC(created_at, MONTH).

  3. Replace the original table

    After you verify the data in events_copy, drop the original table:

    SQL
    DROP TABLE artie.events;

    Then rename the copy:

    SQL
    ALTER TABLE artie.events_copy RENAME TO events;
  4. Update the table's settings in Artie

    On the pipeline page, select Edit pipeline, then the Tables tab. On the events row, select Advanced settings.

    Under Optimizations, turn on Use a merge predicate and select created_at in Column name. Set Partition granularity to match how you partitioned the table, then select Close.

    Artie then filters each merge on the partition column, so BigQuery prunes partitions during merges. See Use a merge predicate for more on this table setting.

  5. Deploy and resume

    Select Save changes, then Deploy. In Validate and deploy, leave Resume pipeline after deployment on, then select Deploy.

    The pipeline resumes and applies the held changes. Then follow Verify partitioning.

Verify partitioning

To confirm partitioning is active, run this query in BigQuery:

SQL
SELECT table_name, partition_id, total_rows
FROM `artie.INFORMATION_SCHEMA.PARTITIONS`
WHERE table_name = 'events'
ORDER BY partition_id;

The query returns one row per partition. A single row with a NULL partition_id means the table isn’t partitioned.

Partitioned tables

A partitioned table is divided into segments called partitions, based on the value of a partition column. A query or merge that filters on that column reads fewer bytes.

Why use table partitions

Partitioning a table that Artie merges into has three effects:

  • Faster merges: Artie’s merges scan only the relevant partitions instead of the entire table.
  • Lower costs: Fewer bytes scanned lowers BigQuery compute charges under on-demand pricing.
  • Partition-level management: Write to, delete or expire individual partitions without affecting the rest of the table.
Estimated from measurements in the blog post BigQuery MERGE Partition Pruning: Why CDC Merges Need a Partition Filter.

Partitioning strategies

BigQuery has three ways to partition a table:

Partitioning typeDescriptionArtie recommendation
Time partitioningPartitions based on a TIMESTAMP, DATE, or DATETIME column. Supports hourly, daily, monthly, and yearly granularity.Recommended. Works well with CDC workloads where data naturally has a time dimension. Artie creates these tables for you.
Integer rangePartitions based on value ranges of an integer column (e.g. customer_id 0–9 in one partition, 10–19 in the next).Useful when your data has no natural time column but has a well-distributed integer key. Create the table in BigQuery yourself.
Ingestion timePartitions based on when rows were inserted into BigQuery.Not recommended. Artie filters merges only on a column from your source table, and the ingestion time isn’t one, so merges can’t prune partitions.

Next steps

Was this page helpful?