1h read

Iceberg Hidden Partitioning: How Query Filters Prune Data

See how Iceberg hidden partitioning maps query filters to transforms. Compare partition pruning with residual filtering and check a Spark SQL example.

Iceberg Hidden Partitioning: How Query Filters Prune Data

Your query filters on event_time. The table is partitioned by days(event_time), a transform you never wrote in a WHERE clause. Iceberg bridges that gap: it projects your predicate into partition space and skips files that cannot possibly match. That translation is hidden partitioning, and it is worth understanding before you trust it.

Before You Start: Prerequisites for the Example

Everything below runs in stock Spark against an Iceberg catalog, so pin your versions before you copy any SQL. You need Apache Spark 3.5 or later, the matching iceberg-spark-runtime JAR on the classpath, a catalog such as spark_catalog pointed at a warehouse directory, and a table you can drop and recreate while you experiment with a layout. Version matters here: the transforms behave consistently, but EXPLAIN formatting shifts between releases, so compare plans produced by the same Spark build.

This walkthrough makes no performance claim. It shows the mechanics of transforms, predicate projection, conservative pruning, and residual row filters, and it stops there. You will read EXPLAIN output and table metadata, not benchmark hardware.

Partition Transforms Define the Physical Layout

A partition spec maps a source column to a transform, and the transform's output decides how rows are grouped into files. The spec lives in table metadata rather than in the schema, so the transformed values never become columns you can select. That separation is the whole trick: users keep writing event_time, and the engine keeps tracking days(event_time) for them.

Iceberg ships a small, fixed set of transforms, described in the official partitioning guide. The year, month, day, and hour transforms work on timestamps and dates and produce a calendar-aligned value. bucket(N, column) hashes a value into a fixed number of buckets, which suits high-cardinality columns such as IDs. truncate(W, column) cuts strings to a prefix or numbers to a multiple, handy when values share a meaningful prefix. identity(column) returns the value unchanged and behaves closest to a traditional partition column.

Pick the transform from your filter patterns rather than from the column's shape. If queries almost always filter on a time range, a day or hour transform gives the planner a coarse but dependable boundary. If they filter on a specific customer or device, bucket concentrates matching rows without inflating the partition count. Combining transforms is normal, and each row simply carries a partition tuple with one value per field. Because that tuple is metadata, the spec can be changed later without rewriting every query, a property explored in this walkthrough of Iceberg partition evolution.

Hidden Transforms vs. Explicit Partition Columns

The choice between hidden transforms and explicit partition columns changes who has to be right about the layout. Hidden partitioning asks the table definition to be correct once; explicit columns ask every query author to be correct every time. The table below compares the two approaches on the properties that tend to decide the argument.

Aspect

Hidden transforms

Explicit partition columns

Query predicate

Filters the source column, such as event_time

Must reference the materialized partition column

Where layout lives

In table metadata, separate from the schema

As real columns in the schema and the SELECT list

Adding a new partition field

Metadata change, no query rewrite

New column, and every insert must populate it

Risk of a stale predicate

Low, since the engine derives the partition filter

High, since a wrong or missing column skips pruning

Insert cost

Derived from source values at write time

The writer must compute and supply the value

Reading the table

Column list matches the source data

Partition columns appear in SELECT *

Evolving the layout

New spec applies going forward

Rewrite or backfill to add columns

Neither approach removes the need to choose the transform from real query patterns, and neither guarantees a fast result on its own. The difference is where the burden lands: on the table definition, where it is decided once and reviewed, or on the query, where it is decided thousands of times with less scrutiny.

Predicate Projection: Translating Filters into Partition Space

Predicate projection is the step that makes hidden partitioning work. When a query arrives, Iceberg takes the predicate on the source column and rewrites it as a predicate on the partition value, using the same transform that wrote the data. For a table partitioned by days(event_time), the filter event_time >= TIMESTAMP '2026-11-01' becomes a bound on the day partition value, roughly event_time_day >= 2026-11-01.

Equality predicates project directly. If the query asks for event_time = TIMESTAMP '2026-11-15 10:00:00', the planner can name the single day partition that could hold the row. For bucket(N, customer_id), an equality on customer_id is handled by computing the same hash the writer used, so customer_id = 8812345 becomes a comparison against one bucket number, and an IN list becomes a set of bucket numbers. The projection is deterministic because both the writer and the reader run identical transform logic.

Projection is where the design earns its keep, and also where it can quietly under-deliver. If your query filters on a column that carries no transform, nothing projects, and the planner reads every manifest. That is not a bug in Iceberg; it is a layout that does not match the workload, and the fix is a partition spec change rather than a query hint.

A Worked Example: Create the Table, Filter It, Read the Plan

Walk through the mechanics in order, and read each artifact rather than trusting a summary.

  1. Create a table with a hidden days transform. In Spark SQL, the statement names the source column and the transform, and never declares event_time_day as a column:

CREATE TABLE local.db.events (
    event_time   TIMESTAMP,
    customer_id  BIGINT,
    event_type   STRING,
    payload      STRING
  )
  USING iceberg
  PARTITIONED BY (days(event_time));
  
  1. Run a timestamp-range query. The filter is written against the logical column, and the range is half-open so the boundary day is unambiguous:

SELECT customer_id, event_type
  FROM local.db.events
  WHERE event_time >= TIMESTAMP '2026-11-01 00:00:00'
    AND event_time <  TIMESTAMP '2026-12-01 00:00:00';
  
  1. Read EXPLAIN and look for the pruning step. Prefixing the query with EXPLAIN returns the logical and physical plans:

EXPLAIN
  SELECT customer_id, event_type
  FROM local.db.events
  WHERE event_time >= TIMESTAMP '2026-11-01 00:00:00'
    AND event_time <  TIMESTAMP '2026-12-01 00:00:00';
  
  1. Confirm the plan shows a filter on the partition value, not only on event_time. The Spark scan node for an Iceberg table exposes partition filters separately from data filters, so the projected event_time_day bound and the original timestamp range should both appear. If only the timestamp range shows up, check that the transform is in the spec and that your Spark build is the one you expect, because the display differs across releases.

  2. Cross-check against table metadata. Querying SELECT * FROM local.db.events.partitions lists the partition tuples Iceberg recorded, which is the ground truth the planner prunes against, as documented in the Spark queries reference.

None of this demonstrates a specific speedup. What it demonstrates is that a predicate on event_time reaches the partition layer at all, which is the precondition for any pruning to happen.

Conservative Partition Pruning and Residual Row Filters

Partition pruning is a filter on files, not on rows, and that distinction explains most surprises. Because the transform is coarser than the predicate, the projected partition filter has to be widened so it never drops a file that might contain a match. For a table partitioned by month(event_time), the predicate event_time = TIMESTAMP '2026-11-30 10:00:00' points at the November partition, but that partition can hold rows from the whole month. Iceberg therefore keeps the partition and lets a later filter remove the rows that do not match. Anyone who reads the projection as an exact row filter will expect the wrong thing from the plan.

Think of it as an inclusive filter with a safety margin. Widening can retain extra files; it must never discard a file that could satisfy the predicate, because that would return wrong results silently. After pruning, three filtering layers handle the remainder, each one working on a smaller candidate set:

  1. Manifest-list pruning. Manifest-list entries hold partition summaries, so manifests whose recorded ranges cannot satisfy the predicate are skipped before their contents are read.

  2. Manifest pruning. For each surviving manifest, the per-file partition tuple excludes files whose transformed values are incompatible with the projected filter.

  3. File and row-group pruning. The remaining files go to the reader, where column statistics like Parquet minimum and maximum values, plus predicate pushdown, discard more files or row groups.

What survives all three layers still contains rows that satisfy the partition predicate but not the full one. That residue is the row filter you wrote in the WHERE clause. Iceberg calls the projection that produces this behavior inclusive projection, and its correctness rule is one-sided on purpose: the partition projection may return more data than requested, never less. So the pair to keep straight is partition pruning, which avoids opening irrelevant files, and predicate pushdown, which removes rows inside the files that are opened. Skipping the second step is how a query prunes aggressively and still returns too many rows.

FAQ

Does hidden partitioning change the files a query reads, or only how fast it runs?

It changes which files the planner considers, and that is the mechanism behind any speed difference. Your SELECT list and WHERE clause stay the same, but the predicate on the source column projects into partition space and the metadata filters out files that cannot match. Whether that saves wall-clock time depends on your data layout, file sizes, and storage, so treat pruning as the cause and speed as a possible effect rather than a guaranteed one.

What happens to a query that filters on a column with no transform?

Nothing projects, and the planner falls back to reading every manifest and data file, so partition pruning does little or nothing. The fix belongs in the table definition: add a transform on the column you filter, such as days(event_time) or bucket(N, customer_id), and write future data under the new spec. Changing the spec will not retroactively reorganize existing files, which is a separate maintenance job.

Why does the plan still show a filter on event_time after pruning?

Because pruning works at the file level and the residual predicate works at the row level, so both remain in the plan. The partition filter removes candidate files, and the data filter, still expressed on event_time, removes rows inside the files that survive. Seeing both is expected and healthy; seeing only the timestamp filter usually means no transform matched the predicate.

How does bucket handle equality and range predicates?

Equality projects cleanly because the reader recomputes the same hash the writer used, so customer_id = 8812345 maps to a single bucket, and an IN list maps to a set of buckets. A range such as customer_id > 8812345 does not map to a contiguous bucket range, because hashing scrambles ordering, so the planner cannot prune by bucket value and may scan more files. bucket suits point lookups, not ranges.

Where can I confirm the partition tuples the planner is using?

Query the table's partitions metadata table, for example SELECT * FROM local.db.events.partitions, which lists the partition values Iceberg wrote, exactly as the Spark queries documentation describes. Compare those tuples against the partitions in your plan to confirm that pruning is working against the layout you intended. If expected partitions are missing, the transform likely does not cover the filtered column.

Where to Go Next

The practical payoff of hidden partitioning is a cleaner schema and fewer ways for a query author to quietly defeat pruning. Your SELECT statements keep referencing real columns, the layout lives in metadata, and the planner handles the translation, so the layout decision is made once and reviewed rather than re-made in every query. What hidden partitioning does not do is choose the right transform for you, or promise that a given query will be fast.

Run the example against your own table, read the plan, and check the metadata, because the layout on disk is the only thing that decides whether pruning helps. If you are evaluating open table formats for a lakehouse, this overview of when a lakehouse beats a data warehouse for BI covers the architectural side, and this CDC delete semantics comparison for Iceberg and Delta digs into how updates and deletes meet partitioned layouts. Singdata builds on an open-lakehouse architecture with native Iceberg support and participates in the Iceberg project, so read that as context on where these mechanics run rather than as evidence for anything above.

Related Articles