Skip to main content

Speed up reads

By default, a model that reads a table from the catalog receives all its columns and rows. You can specify filters and projections to narrow the scan on object storage, which reduces memory, I/O and latency. Filters (WHERE in SQL) reduce the number of rows. Projections (SELECT in SQL) reduce the number of columns.

Declare, for every catalog input of a model, the necessary columns and filter unnecessary rows.

from typing import Annotated

import bauplan
import pyarrow as pa


class EventColumns(bauplan.TableSchema):
"""The event columns needed for the reporting window."""

event_id: bauplan.String
account_id: bauplan.String
event_type: bauplan.String
event_date: bauplan.Date32


@bauplan.model()
@bauplan.python("3.13")
def report(
events: Annotated[
pa.Table,
bauplan.Model(
"raw.events",
projection_schema=EventColumns, # Only some columns are read
filter="event_date >= $start_date", # Only some rows are read
),
],
) -> Annotated[pa.Table, EventColumns]:
"""Events of the reporting window."""
...

Select only the columns the model uses

Give every catalog input of a model a projection_schema that lists only the columns the model uses, as EventColumns does above, and do not read a catalog table without one. Only the projected columns are fetched, and the others are never downloaded from object storage or loaded into memory.

Filter rows where the model reads them

Add a filter to the input declaration that drops the rows the model would discard anyway. Bauplan pushes the filter into the scan, where it prunes whole files using partition values and file statistics before anything is read. Filtering inside the function pays for the full read on every run, whereas a catalog filter never reads the files it can skip and never loads the rows it excludes into the model.

The filter is best used with run parameters, as $start_date above, and the same model then serves every window; see how to parametrize a pipeline. Write the filter as a string literal, and do not build it with an f-string or from a variable. Bauplan reads the filter from the code of the model before it runs anything, and rejects a filter that is not a string literal.

filter="event_date >= $start_date" # accepted: a string literal with a run parameter
filter=f"event_date >= {start_date}" # rejected: built at run time, so Bauplan cannot read it

Compare top-level columns directly

Bauplan can skip files only for conditions that compare a top-level column with a value:

event_date >= '2026-09-01' -- skips files
upper(country) = 'IT' -- reads every file, then filters
payload['country'] = 'IT' -- reads every file, then filters

If you often filter on a nested field, store it as a top-level column when you ingest the data, as in extract only the nested fields you need.

Filters on partition columns are the most effective, because they exclude whole partitions. On other columns, a filter skips files only if the values are grouped by file, for instance when the data is sorted on that column. See how to partition tables in a pipeline.