Using Artie
Rebuild and swap backfills
Reload a Snowflake or Databricks table without downtime. Artie backfills a new table and swaps it in, so data stays queryable.
Rebuild and swap is a backfill option. The destination table keeps serving its rows until every backfilled row is loaded, then Artie replaces them in one step:
- Snowflake: Artie swaps the two tables with
ALTER TABLE ... SWAP WITH, which is atomic. - Databricks: Databricks can’t swap tables, so Artie overwrites the destination table’s rows with
INSERT OVERWRITEin one Delta commit. Readers see either every old row or every new one.
Use it to:
- Fully reload a table that dashboards, dbt models or other jobs query continuously, without an empty or partially loaded window.
- Reload 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 to compare against or roll back to.
Prerequisites
- Rebuild and swap is enabled for your account.
- The destination is Snowflake or Databricks.
- The table isn’t a history table or a dynamic table, and doesn’t use soft partitioning. See Limitations.
- The schema has room for a second copy of the table.
- Snowflake: Artie’s role owns the destination table and has
CREATE TABLEon its schema. - Databricks: the table has no identity column.
Until the feature is enabled, the Rebuild and swap option doesn’t appear in the backfill dialog. The API returns rebuild and swap backfills are not enabled for this company.
The rebuild table holds a full copy of the table while the backfill runs. The old rows also stay after the swap if you keep them for rollback.
Confirm table ownership in Snowflake
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 holds unless someone transferred ownership to another role.
Run this in Snowflake to check the owner:
SHOW GRANTS ON TABLE ANALYTICS.PUBLIC.ORDERS;The row with privilege = OWNERSHIP names the owner. It must be the role Artie connects with. These examples use ARTIE_TRANSFER_ROLE, the default in the service account script. Replace it with your role’s name.
If another role owns the table, transfer ownership back:
GRANT OWNERSHIP ON TABLE ANALYTICS.PUBLIC.ORDERS TO ROLE ARTIE_TRANSFER_ROLE COPY CURRENT GRANTS;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. Grants such as ALL PRIVILEGES don’t include OWNERSHIP.
The service account script grants ALL PRIVILEGES on the destination schema, which covers CREATE TABLE.
Check for identity columns in Databricks
The overwrite gives an identity column new values, so Artie blocks these tables before the backfill starts. The backfill dialog shows this error:
These tables can't be rebuilt and swapped: <table> (has an identity column, which a rebuild would renumber). Deselect them or choose Keep existing rows.Deselect the table and backfill it with another option. If Artie can’t read the table’s columns, the reason is couldn't be checked for identity columns instead. Tables that aren’t in Databricks yet aren’t checked, since they have no rows to keep.
Run a rebuild and swap backfill
Open the backfill dialog
On the pipeline’s overview page, open the More options menu and select Backfill tables….
Select the tables
Select the tables to reload, then select Continue.
Select Rebuild and swap
In the Existing rows step, select Rebuild and swap, then select Continue.
To keep the pre-swap rows, also check Keep the old table for rollback, until the next rebuild and swap. See Roll back a swap.
For a Databricks destination, Artie checks the selected tables for identity columns at this point.
Choose a backfill speed
In the Speed step, choose a speed, then select Continue. Artie saves it as the pipeline’s backfill speed.
If other pipelines share the source’s settings, the step is read-only and says where to change the speed.
Start the backfill
In the Review step, select Start backfill.
Existing rows reads Rebuild and swap, or Rebuild and swap, keep old table if you kept the old rows.
Pipelines with tables unified across schemas or databases open a different Backfill tables dialog. Select the tables and Backfill selected tables, then choose Rebuild and swap in the confirmation. Picking specific schemas or databases there hides the option, and the backfill keeps existing rows. For Databricks, Artie checks for identity columns when you select Start backfill.
The backfill dialog for pipelines with a DynamoDB source doesn’t offer Rebuild and swap.
Row counts and progress in the dashboard show under the destination table’s name, although the backfill writes to the rebuild table. When you select more than one table, each table swaps as soon as its own backfill finishes.
Start the backfill through the API
Call Backfill pipeline tables with beforeBackfill set to swap_table. Run this from your terminal:
curl -X POST "https://api.artie.com/pipelines/7f1c2a9e-4b3d-4e8a-9c61-2d5f0b8e3a17/backfill" \
-H "Authorization: Bearer $ARTIE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"tableUUIDs": ["c3e8a1d4-5f2b-4a9c-8e7d-1b6f3c0a9e52"],
"beforeBackfill": "swap_table",
"keepOldTable": true
}'Replace the UUID in the URL with your pipeline’s UUID and the tableUUIDs values with your tables’ UUIDs. ARTIE_API_KEY is your API key. keepOldTable keeps the old rows until the next swap_table backfill of that table.
Recreate Snowflake streams
A Snowflake stream follows the table object, not its name. After the swap, existing streams track the old rows, and they go stale once that table is dropped. If the table has streams, recreate them on the rebuilt table.
Rebuild tables
Artie backfills into a rebuild table named <TABLE>___artie_<suffix>, where <suffix> is five random characters generated for each attempt. Jobs that skip Artie’s working tables by the ___artie marker skip the rebuild table too. See Rebuild table names.
While the backfill runs, change data capture (CDC) changes for the table are held in Kafka, as with any backfill. The destination table keeps the rows it had when the backfill started. When the backfill completes, Artie swaps the tables, drops the old rows unless you kept them, and applies the held changes to the rebuilt table. The table then goes back to streaming.
The rebuild table is a regular table in the same schema, and it fills up as the backfill runs. Query it if you need to, but don’t write to it or rename it, since Artie swaps it in by name.
Rebuild tables in Snowflake
Artie creates the rebuild table with CREATE OR REPLACE TABLE ... CLONE ... COPY GRANTS, then empties it. Cloning copies no data, so creating the rebuild table is fast at any table size. The swap is a single ALTER TABLE ... SWAP WITH statement.
Rebuild tables in Databricks
Artie creates the rebuild table empty with CREATE TABLE ... LIKE, which copies the destination table’s columns, comments, constraints, clustering and table properties. At the cutover, Artie adds any new source columns to the destination table, then runs INSERT OVERWRITE from the rebuild table.
The destination table stays the same table, so its grants, tags, comments, constraints and Delta history are unchanged. Unity Catalog stores table names in lowercase, so the rebuild table appears as <table>___artie_<suffix>.
Canceled, failed and retried backfills
The destination table is unchanged if you cancel the backfill or it fails, since it only changes at the swap. The partly loaded rebuild table stays in the schema until the next rebuild and swap of that table. That backfill is a new attempt with a new suffix, and it drops the previous attempt’s rebuild table before it starts loading.
Retrying a failed table restarts it with Keep existing rows, so the retry loads into the destination table in place. This applies to Retry table and Retry N failed tables on the backfill progress card, and Retry backfill in the tables list.
A failed table still counts as backfilling, so a new backfill skips it. To rebuild and swap it again, open the More options menu and select Cancel backfill…. Select the failed table, cancel it, then start a new backfill with Rebuild and swap.
Rebuild table names
Rebuild tables use the same ___artie marker as Artie’s other working tables, followed by five random characters. Temporary tables end in a Unix timestamp instead, and kept Databricks copies can end in ___artie_old. This table uses ORDERS as the destination table:
| Table | What it is | When it goes away |
|---|---|---|
ORDERS___ARTIE_K3P9X | A rebuild table. During the backfill it holds the rows being loaded. After the swap it holds the old rows, if you kept them. | When the next rebuild and swap of ORDERS starts. Artie never drops it on a timer. |
ORDERS___ARTIE_AB12C_1792776403 | A temporary table Artie uses while writing to ORDERS. | Artie drops it after the timestamp at the end has passed. |
ORDERS___ARTIE_K3P9X___ARTIE_AB12C_1792776403 | A temporary table Artie uses while writing to the rebuild table. | Artie drops it after the timestamp at the end has passed. |
orders___artie_k3p9x___artie_old | Databricks only. The kept old rows, if Artie couldn’t move them to the rebuild table’s name after the swap. | When the next rebuild and swap of orders starts. |
ORDERS___ARTIE_MSM | A working table Artie reuses for large merges. | Artie keeps reusing it. Leave it in place. |
To list only the rebuild tables in a Snowflake schema, for example to find kept tables you want to drop, run:
SELECT table_name, created
FROM ANALYTICS.INFORMATION_SCHEMA.TABLES
WHERE table_schema = 'PUBLIC'
AND REGEXP_LIKE(table_name, '.+___ARTIE_[A-Z0-9]{5}', 'i')
ORDER BY created;What carries over
In Databricks, the destination table isn’t replaced, only its rows, so everything on the table carries over. Old rows stay reachable through Delta time travel until VACUUM removes them.
In Snowflake, the rebuild table is a Snowflake clone of the destination table, created with COPY GRANTS. This table lists what the Snowflake table has after the swap:
| Property | After the swap |
|---|---|
| Columns and data types | Kept. The rebuild starts from the destination table’s current columns, and new source columns are added during the backfill as usual. |
| Grants | Kept, except OWNERSHIP, which stays with Artie’s role. |
| Tags | Kept. |
| Masking and row access policies | Kept. |
| Table and column comments | Kept. |
| Clustering key | Kept. Snowflake suspends automatic clustering on a clone, so Artie resumes it on the rebuild table before the swap. If that fails, the backfill fails with failed to resume automatic clustering on <table> and the destination table is unchanged. |
| Search optimization | Kept. |
Object parameters, such as DATA_RETENTION_TIME_IN_DAYS | Kept. |
| Views on the table | Keep working. Views resolve the table by name. |
| Streams on the table | Not carried over. Recreate them. |
| Time Travel history | Starts when the rebuild table was created. Older history stays with the old table. |
| Rows no longer in the source | Removed. The rebuilt table only has rows the backfill read from the source. |
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>___artie_<suffix> after the swap. They stay 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.
A table kept by a rebuild that ran before the marker was added is named <TABLE>_<suffix> instead. The next rebuild and swap still drops it.
Roll back in Databricks
The kept rows are a deep clone of the destination table, so a VACUUM on the destination table can’t remove them. If Artie can’t move the clone to the rebuild table’s name, the old rows stay in <table>___artie_<suffix>___artie_old.
Without the option, roll back with RESTORE TABLE ... TO VERSION AS OF <version> until VACUUM removes the old files. Run DESCRIBE HISTORY on the table to find the version before the INSERT OVERWRITE.
Roll back in Snowflake
Run this to find the kept table:
SHOW TABLES LIKE 'ORDERS\\_%' IN SCHEMA ANALYTICS.PUBLIC;Then swap it back as Artie’s role, which owns both tables:
ALTER TABLE ANALYTICS.PUBLIC.ORDERS SWAP WITH ANALYTICS.PUBLIC.ORDERS___ARTIE_K3P9X;Compare backfill options
The four options in the Existing rows step differ in what queries see during the backfill and what the table keeps:
| Property | Keep existing rows | Empty tables first | Drop and recreate | Rebuild and swap |
|---|---|---|---|---|
| Table during the backfill | Current rows, updated in place | Empty, then partially loaded | Missing, then partially loaded | Current rows, unchanged |
| Removes rows no longer in the source | No | Yes | Yes | Yes |
| Keeps grants, tags and policies | Yes | Yes | No | Yes |
| Table if the backfill fails | Partially updated | Partially loaded | Partially loaded | Unchanged |
| Extra storage | None | None | None | A second copy of the table |
| Destinations | All | All except Kafka | All except Kafka | Snowflake, Databricks |
Limitations
- Snowflake and Databricks 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 and Databricks destinations. Use Empty tables first or Drop and recreate instead. Kafka destinations offer neither, so a backfill publishes on top of the existing messages. - Databricks: no identity columns. See Check for identity columns in Databricks.
- 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 Empty tables first or Drop and recreate for history tables. - No dynamic tables. A swap would replace the dynamic table’s view with a regular table. The API rejects it with
table "<table>" uses a dynamic table, so it can only be backfilled after truncating or dropping it. Use Empty tables first or Drop and recreate for dynamic tables. - Whole tables only. The swap replaces the whole table, so the backfill has to cover every row. In the dashboard, picking specific source schemas or databases hides the option. The API rejects such a backfill with
cannot drop/truncate tables before backfilling if only backfilling from certain schemas(orcertain databases). Backfill those with Keep existing rows. - No soft partitioning. The backfill fails before loading any rows with
swapping tables is not supported with soft partitioning. Use Empty tables first or Drop and recreate for tables with soft partitioning.
Was this page helpful?
- Need help? Message us on Slack or email [email protected].
- Want a walkthrough? Book a demo.
- LLM? Read llms.txt.