Skip to main content

Mastering data loading in BigQuery using Dataform

Prasanna Venkatesan•7 February 2025•3 min read
Mastering data loading in BigQuery using Dataform

Efficient data loading is crucial for managing and updating tables in Dataform. Various strategies exist to handle different use cases, including truncate and load, appending data, and leveraging incremental tables with unique keys. This blog explores these primary methods and more:

Truncate and Load

In this method, all existing records in the target table are deleted and replaced with a fresh table. This approach works well when a full table refresh is necessary or if managing slowly changing data.

Implementation in Dataform:

  • Set the table type to table.

Example:

config {
  type: "table"
}

SELECT
  id,
  name,
  timestamp
FROM
  ${ref("source_table")}

By defining the table type as table, Dataform ensures that each run recreates the table, effectively performing a truncate and load operation.

Append or Insert-Only Loads

This method appends new data to an existing table while preserving historical records. It is ideal for use cases where past data must remain unchanged, and only new records are added.

Implementation in Dataform:

  • Set the table type to incremental.
  • Define an incremental condition to capture only new records.

Example:

config {
  type: "incremental"
}

SELECT
  id,
  name,
  timestamp
FROM
  ${ref("source_table")}
WHERE
  timestamp = CURRENT_DATE() - 2

This ensures that only records from two days ago, based on CURRENT_DATE() - 2, are appended to the target table.

Incremental Loads with Unique Keys

This method ensures that only one row per unique key is retained and updates existing records if changes occur. This is useful for deduplicating or updating records efficiently.

30-minute consultation


Book your free Dataform consultation

✓ Infrastructure audit ✓ Transformation plan ✓ Efficiency analysis

Implementation in Dataform:

  • Set the table type to incremental.
  • Define an uniqueKey to update existing records with new data instead of inserting duplicates.

Example:

config {
  type: "incremental",
  uniqueKey: "id"
}

SELECT
  id,
  name,
  position,
  timestamp
FROM
  ${ref("source_table")}
WHERE
  timestamp = CURRENT_DATE() - 2

Dataform automatically handles the merge process—if a record with the same id already exists, it gets updated. If a new id appears, it is inserted as a new row.

Incremental Load with Rolling Delete

This method ensures that before inserting new data incrementally, the system deletes records from the last two days to accommodate any late-arriving updates. This is useful for ensuring data freshness while still maintaining an incremental approach.

Implementation in Dataform:

  • Set the table type to incremental.
  • Use a pre-operation delete step to remove data from the last two days before inserting new records.

Example:

config {
  type: "incremental"
}

pre_operations {
  DELETE 
  FROM 
    ${self()} 
  WHERE 
    timestamp >= CURRENT_DATE() - 2;
  }

  SELECT
    id,
    name,
    position,
    timestamp
  FROM
    ${ref("source_table")}
  WHERE
    timestamp >= CURRENT_DATE() - 2

This ensures that any late-arriving updates from the last two days are reflected correctly while keeping the rest of the data intact.

Choosing the Right Method in Dataform

MethodBest Use Case
Truncate and LoadWhen a full table refresh is needed.
Append or Insert-Only When historical records must be preserved.
Incremental Load with Unique KeysWhen deduplication and updates are required.
Incremental Load with Rolling DeleteWhen handling late-arriving updates for the last n number of days.

Understanding these approaches in Dataform allows you to optimise your ETL/ELT workflows and effectively manage data changes for various use cases in BigQuery and other Data Warehouses.

Have you used any of these methods in Dataform? Reach out to let us know, and contact us if we can help you with anything Dataform/BigQuery related! 🚀

Need help with your data platform?

We build intelligence platforms on BigQuery, Dataform and Google Cloud - from setup to ongoing optimisation.

How ready is your data?

Take our short assessment to find out where your data stack stands and what to prioritise next.


Suggested content

How to make an AI agent accurate in BigQuery

A year ago, I wrote about getting a BigQuery warehouse ready for AI ( Easy ways to prepare your BigQuery warehouse for AI) , but didn't look properly into Knowledge Catalog (known as Dataplex at the time). We decided to go back and look through Google's Knowledge Catalog properly: what's actually in there, how it works and what it relates to. What Knowledge Catalog is Knowledge Catalog is Google's metadata layer for BigQuery data (and a few other sources). It sits alongside your tables rather

Katie Kaczmarek•15 Sept 2026

What's actually in Google's Knowledge Catalog

Google's Knowledge Catalog has been renamed four times. Data Catalog, then Dataplex Catalog, then BigQuery universal catalog, then Dataplex Universal Catalog, and now Knowledge Catalog, as of 10 April 2026. The API, gcloud and IAM roles still all say "dataplex". If you land on a page that mentions Dataplex and wonder whether you're reading something out of date, you're probably not. That's just the product's fifth name in four years. I spent some time looking through the different sections of K

Katie Kaczmarek•15 Sept 2026

BigQuery Tips: When your query is technically correct but BigQuery won't run it

There is a particular kind of frustration that comes from staring at a query you know is correct and watching it fail. No syntax error. No logic problem. Just a wall. We hit two of them on the same project. What we were building The job was to migrate ga4_daily_snapshot for a large enterprise client from a BigQuery scheduled query into a proper Dataform pipeline. The scheduled query had been added to over time until it was too large to maintain with any confidence. Moving it to Dataform w

Katie Kaczmarek•17 Aug 2026