Overview
Rebuild and swap is a backfill option for Snowflake destinations. Artie loads the backfill into a separate table next to the destination table, then swaps the two withALTER TABLE ... SWAP WITH once every row is loaded. The destination table keeps serving its current rows until the swap, and the swap itself is atomic.
Use this when you want to:
- Fully reload a table that dashboards, dbt models or other jobs query continuously, without an empty or partially loaded window.
- Re-sync a table whose data has drifted from the source, including rows that were deleted at the source but are still in the destination.
- Keep the pre-reload data around to compare against or roll back to.
How it works
Artie backfills into a rebuild table named<TABLE>_<suffix>, where <suffix> is five random characters generated for each attempt. While the backfill runs, CDC changes for the table are held in Kafka, so the destination table keeps the rows it had when the backfill started. When the backfill completes, Artie swaps the tables, drops the old rows, and applies the held changes to the rebuilt table.
In Snowflake, the rebuild table is created with CREATE OR REPLACE TABLE ... CLONE ... COPY GRANTS, and the swap is a single ALTER TABLE ... SWAP WITH statement. Cloning copies no data, so creating the rebuild table is fast at any table size.
<TABLE>_<suffix>, but row counts and progress in the dashboard show under the destination table’s name. When you select more than one table, each table swaps as soon as its own backfill finishes.Before you start
-
Feature needs to be enabled. Until it is, the Rebuild and swap option doesn’t appear in the backfill dialog, and the API returns
rebuild and swap backfills are not enabled for this company. -
Artie’s role owns the destination table. The swap renames the destination table, and Snowflake only lets the table’s owner do that. Artie creates destination tables with its own role, so this is already true unless someone transferred ownership of the table to another role. Check the owner:
The row with
privilege = OWNERSHIPshould name the role Artie connects with. These examples useARTIE_TRANSFER_ROLE, the default in the service account script. Replace it with your role’s name. If another role owns the table, transfer it back: -
Artie’s role has
CREATE TABLEon the destination schema. The service account script grants this. - The schema has room for a second copy of the table. The rebuild table holds a full copy while the backfill runs, and the old rows stay after the swap if you keep them.
Steps
Open the backfill dialog
Select Rebuild and swap
Start the backfill
beforeBackfill set to swap_table:Resume automatic clustering, if the table used it
Recreate streams on the table, if you have any
What carries over
The rebuild table is a Snowflake clone of the destination table, created withCOPY GRANTS.
Roll back a swap
With Keep the old table for rollback, until the next rebuild and swap checked, Artie leaves the old rows in<TABLE>_<suffix> after the swap. They stay there until the next rebuild and swap of the same table, which drops them before it starts loading. Unchecked, Artie drops the old rows right after the swap.
Find the kept table:
Limitations
- Snowflake only. The dashboard doesn’t offer the option for other destinations, and the API rejects it with
rebuild and swap backfills are only supported for Snowflake destinations. Use Truncate or Drop table instead. - No history tables. A history table keeps rows the source no longer has, and a rebuild would drop them. The API rejects it with
history tables cannot be backfilled with rebuild and swap. Use Truncate or Drop table for history tables. - Whole tables only. The swap replaces the whole table, so the backfill has to cover every row:
- A backfill limited to specific source schemas or databases is rejected with
cannot drop/truncate tables before backfilling if only backfilling from certain schemas(orcertain databases). Backfill those with Do nothing. - A restart limited to a primary key range is rejected with
a rebuild and swap backfill cannot be limited to a primary key range. Restart without a range.
- A backfill limited to specific source schemas or databases is rejected with
- No soft partitioning. The backfill fails before loading any rows with
swapping tables is not supported with soft partitioning. Use Truncate or Drop table for tables with soft partitioning.
Frequently asked questions
Does the destination table get CDC changes during the backfill?
Does the destination table get CDC changes during the backfill?
What happens if I cancel the backfill, or it fails?
What happens if I cancel the backfill, or it fails?
What happens if I restart the backfill?
What happens if I restart the backfill?
Can I query the rebuild table while the backfill runs?
Can I query the rebuild table while the backfill runs?
<TABLE>_<suffix> is a regular table in the same schema and fills up as the backfill runs. Don’t write to it or rename it, since Artie swaps it in by name.Why does Artie's role need to own the destination table?
Why does Artie's role need to own the destination table?
ALTER TABLE ... SWAP WITH renames both tables, and Snowflake requires the role running it to have OWNERSHIP on both. Artie’s role owns the rebuild table because it created it. The destination table is renamed too, so Artie’s role has to own it as well. Grants such as ALL PRIVILEGES don’t include OWNERSHIP.