Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
dbt Labs · dbt Analytics Engineering

Microbatch, Python Models, --empty, and --sample

dbt Analytics Engineering · Lesson 8 of 17 · 54:31

YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗

Learning with these videos? Subscribe for new courses and exam-style questions.

In this lesson

Prepare for the dbt Analytics Engineering Certification exam. In this lesson: the microbatch strategy (event_time, begin, batch_size, lookback, and backfills), Python models and their materializations, the --empty flag for dry runs, and the --sample flag for development. Includes three original practice questions, with Orchardline Meal Kits, a fictional meal-kit company, as the example.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

Five years of events, and a churn score

Orchardline wants a churn score from a Python machine learning library, and its delivery events now span five years of data. Every developer change also rebuilds tables with billions of rows, just to check that the SQL is right. This lesson covers microbatch models, Python models, and two development flags: empty and sample.

Microbatch

Microbatch is an incremental strategy for large time series: dbt splits the processing into batches, each covering one bounded period of time. You configure event time, the column that says when a row occurred, a begin date for the first build, and a batch size of hour, day, month, or year. The model needs no is incremental block: dbt filters the model's inputs automatically, for every upstream source or ref that also declares an event time. Each batch is atomic and can be rerun safely, so batches can run in parallel, a lookback of one batch by default catches late records, and dbt retry reprocesses only the batches that failed. To reprocess history, run a targeted backfill with event time start and event time end, and set full refresh to false, so that a stray full refresh never reloads everything.

Python models

A Python model is a py file in the models folder that defines a function named model, which takes dbt and session as arguments, and returns a single DataFrame. It reads other nodes with dbt dot ref and dbt dot source, so it takes part in the DAG like any SQL model, and dbt dot config sets its configuration. All the Python code runs remotely, on the data platform, and only some platforms support it, like Snowflake, Databricks, and BigQuery. Python models can only be materialized as table or incremental, never as view or ephemeral, and tests and snapshots cannot be written in Python. Python models do not use Jinja, so for incremental logic, they check dbt dot is incremental, and read the existing table through dbt dot this.

The empty flag

The empty flag validates a model's logic and schema without the cost of building it with data. With run, build, snapshot, or compile, it limits every ref and source to zero rows, so dbt executes the SQL and creates empty tables and views in your development schema. That catches syntax errors, missing columns, and type mismatches quickly. But tests then run against zero rows, so they say nothing about the real data, and Python models ignore the flag.

The sample flag

The sample flag goes one step further than empty: run and build create real tables in your development schema, with only a time based sample of the data. A relative sample, like three days or six hours, takes the most recent data, while a static range, with a start and an end, picks a specific period, like your busiest week. Sampling filters refs and sources by their event time, so the sampled inputs must declare it. To keep one ref unsampled, like a small dimension that every row joins, append dot render to it. Seeds are still loaded in full, but sampled when downstream nodes read them, and Python models ignore the flag.

Recap

Let's recap. Microbatch splits large time series into atomic batches, by event time, begin, and batch size, with no is incremental block. Upstream inputs are filtered only when they declare an event time, and dbt retry reruns only the failed batches. Python models define a model function that returns a DataFrame, run on the platform, and are tables or incremental models only. The empty flag validates logic and schema with zero rows. And the sample flag builds real tables with a time based sample of the data.

Quick checks for this lesson

The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.

  1. The microbatch model reads the delivery events staging model, but each daily batch scans the whole staging table. What is missing?

    • An is_incremental() block in the microbatch model
    • A unique_key on the microbatch model
    • A larger batch_size, such as month
    • An event_time config on the staging model
    Show the answer

    An event_time config on the staging model

    Dbt only filters an upstream model automatically when that model declares its own event time. “An is_incremental() block in the microbatch model” is wrong, since microbatch models need no is incremental block, because dbt adds the filter itself. “A unique_key on the microbatch model” is wrong, since a unique key matches rows in the target, and does not filter the inputs. And “A larger batch_size, such as month” would only reduce the number of batches, each one still scanning the whole table.

  2. A developer writes a Python model for the churn score, and it inherits the view materialization of its folder, like the SQL models next to it. What should the developer know?

    • dbt builds it as a view, like the SQL models
    • dbt builds it as an ephemeral model instead
    • Python models must be tables or incremental models
    • dbt translates the Python code into a SQL view
    Show the answer

    Python models must be tables or incremental models

    Python models can only be tables or incremental models, so this one needs its own materialization. “dbt builds it as a view, like the SQL models” is wrong, since a Python model can never be a view. “dbt builds it as an ephemeral model instead” is wrong, since ephemeral is not allowed for Python models either. And “dbt translates the Python code into a SQL view” is wrong, since the Python code runs on the platform as Python, and dbt never translates it into SQL.

  3. A developer wants to build the deliveries mart in development, with real data from the last three days only, to check its join results. Which command fits?

    • dbt build -s "deliveries" --empty
    • dbt build -s "deliveries" --sample="3 days"
    • dbt show -s "deliveries" --limit 3
    • dbt build -s "deliveries" --full-refresh
    Show the answer

    dbt build -s "deliveries" --sample="3 days"

    Sample mode builds real tables, with only the last 3 days of data from the inputs that declare an event time. “dbt build -s "deliveries" --empty” is wrong, since empty builds the model with zero rows, so no join results appear. “dbt show -s "deliveries" --limit 3” is wrong, since dbt show prints three rows, and builds nothing. And “dbt build -s "deliveries" --full-refresh” is wrong, since a full refresh rebuilds incremental models with all of the data.