Skip to content

Keep the NULL partition in Iceberg data file pruning when the filter's set holds NULL - #130177

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-iceberg-file-pruning-null-in-set
Nov 8, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-iceberg-file-pruning-null-in-set

Conversation

@groeneai

@groeneai groeneai commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #130040
Related: #130158

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed Iceberg partition pruning skipping the data files of a NULL partition when the filter's set holds NULL, such as has([NULL, 1], b).

Description

On 26.10.2.103, SELECT arraySort(groupArray(v)) FROM icebergLocal('<dir>/db/t') WHERE has([NULL, 1], b) over a Spark-written Iceberg table partitioned by a nullable b returns [] instead of [2]; it is correct with use_iceberg_partition_pruning = 0. 26.9.25.15 is the same.

The data-file partition key is built over the non-Nullable source types, so KeyCondition drops the NULL element of the set, while ManifestFilesPruner evaluates a NULL partition value as +inf. Nothing in the set matches it, and the file is skipped.

ManifestFilesPruner now evaluates a partition tuple that holds NULL against the same key built over Nullable inputs. Tuples without NULL keep the existing condition, so pruning of every other file is unchanged: a Nullable key for all files would stop pruning has([NULL, 5], b) on tables without a NULL partition, which the test checks.

Scope: on master the manifest-list pruner drops the same partition too, which #130158 fixes. b IN (NULL, 1) with transform_null_in = 1 also needs #128570 and #128575 (Parquet reader) to return the NULL rows; here only its pruned-file count is tested. The DeltaLake partition pruner strips Nullable the same way and gives the same wrong result; it is not changed here.

Validation: the new test 05575_iceberg_partition_pruning_null_in_set fails on master and passes with the fix (50 randomized runs); the Iceberg stateless tests and the Spark partition-pruning integration suites pass.


Workflow [PR]
Sync PR [sync-upstream/pr/130177]

Version info

  • Merged into: 26.11.1.1699-master (included in 26.11 and later)

groeneai and others added 2 commits November 8, 2026 15:58
…s set holds NULL

The data-file partition key is built from removeNullable(source type), and
ManifestFilesPruner evaluates a NULL partition value as the single point +inf.
For a non-Nullable key KeyCondition drops every NULL set element, so
has([NULL, 1], b) became {1}, nothing matched +inf, and the data file of the
NULL partition was skipped. Dropping the NULL element is exact only for a
partition tuple without NULL.

The pruner now also builds the same key over Nullable inputs, with its own
condition, and uses that pair only for a partition tuple holding NULL in a
Nullable key position (a void field has type Tuple() and never selects it).
Every other tuple keeps the existing key and condition.

A Nullable key for every file is not used: for an untyped set holding NULL,
such as [NULL, 5] (Array(Nullable(UInt8))), the has() atom is declined for a
Nullable(Int64) key (not safely castable, and canBeInsideNullable() is false
for a Nullable key), so files of tables without a NULL partition would no
longer be pruned. Accepting a Nullable key at that KeyCondition guard would
give the untyped set the typed shape that the Parquet row-group filter still
gets wrong (ClickHouse#128570, ClickHouse#128575), and is MergeTree-wide.

The manifest-list pruner (master only) is fixed separately by ClickHouse#130158.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the NULL-tuple key selection comment in ManifestFilesPruner::canBePruned to one line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own review (3 nits, none blocking).

# Sev Finding Verdict Evidence / action
1 💡 The Nullable key and its condition are built for every pruner (per manifest and schema) DISAGREE Measured: 200 manifests, median 18/17 ms vs 19/21 ms (debug build), within noise
2 💡 No test arm for a multi-field partition with NULL in one field DISAGREE Checked locally on PARTITION BY (a, b): rows equal with and without pruning, b = 5 and typed sets prune as before
3 💡 A file whose tuple holds NULL in another field is no longer pruned by an untyped NULL-holding has([NULL, 5], b) (2 -> 1 files) DISAGREE Narrow (multi-field spec + NULL in another field + that set shape); same as MergeTree with a Nullable key, which never prunes that set shape; rows are correct

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261108-161900

@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. has([NULL, 1], b) over an Iceberg table partitioned by a nullable b with a NULL partition returns [] instead of [2] on every run, on master, 26.10.2.103 and 26.9.25.15 (also with a Spark-written table).
b Root cause explained? The data-file partition key is built over non-Nullable types, so KeyCondition drops the NULL set element, while the pruner evaluates a NULL partition value as +inf; nothing matches and the file is skipped.
c Fix matches root cause? Yes. A partition tuple that holds NULL is evaluated against the same key over Nullable inputs; tuples without NULL keep the existing condition. No special-casing of files.
d Test intent preserved / new tests added? New stateless test 05575_iceberg_partition_pruning_null_in_set: row arms with pruning off/on, pruned-file counts, NULL-rejecting sentinels, and a table without a NULL partition that checks pruning is not lost.
e Both directions demonstrated? Fails on master (rows and counts), passes with the fix; 50/50 randomized and 50/50 non-randomized runs. A mutation that always uses the old key fails like master; one that always uses the Nullable key loses pruning on the sentinels.
f Fix is general across code paths? Both users of ManifestFilesPruner (reads and the read estimate) get it. The manifest-list pruner is fixed by #130158. The DeltaLake pruner has the same convention and is not changed here.
g Fix generalizes across inputs (params/datatypes/wrappers)? Untyped and typed NULL sets, NOT has, IN with transform_null_in, IS NULL, IS NOT NULL, =, <; identity, bucket, truncate and time transforms (Spark integration suites); void fields are excluded by type.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, format or persisted state; only pruning of files whose partition tuple holds NULL changes, towards correct results.
i Invariants and contracts preserved? canBePruned stays const; the key and its condition are always taken as a pair built from the same definition, so arity and types agree; the second condition is built once and only read.

Session id: cron:clickhouse-impl-slot-7:20261108-150100

@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12 @kssenii, could you review this and add the can be tested label so CI runs? The Iceberg data-file pruner now evaluates a partition tuple that holds NULL against the same key built over Nullable inputs, so has([NULL, 1], b) no longer skips the NULL partition's files; tuples without NULL keep the existing condition.

@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3a9f806]

Summary: ✅


AI Review

Summary

The PR fixes Iceberg data-file pruning discarding a NULL partition for filters such as has([NULL, 1], b) by evaluating tuples containing NULL with a matching Nullable key and condition. Reviewed all changed files at 3a9f8064c3645bcbb7de28bc7a55e4694a43d664, the read and read-estimate callers, partition transforms, schema handling, and prior discussion. No actionable findings.

Missing context / blind spots
  • ⚠️ No local ClickHouse binary or build was available, so this review did not execute the regression test. The PR reports successful before/after and randomized runs. The current CI workflow is still pending; Fast test excludes this Avro-dependent test. A completed Avro-enabled run of 05575_iceberg_partition_pruning_null_in_set would close the independent runtime-validation gap.
Final Verdict

✅ Approve. No code changes requested. Runtime CI validation remains pending.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default can be tested Allows running workflows for external contributors comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 3a9f8064c with master 634d83a99 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

35 translation units recompiled, 397 s compile time in total, 35 of them have a recent master baseline.

Job report

@alexey-milovidov alexey-milovidov self-assigned this Nov 8, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 8, 2026
Merged via the queue into ClickHouse:master with commit fedcee8 Nov 8, 2026
373 of 375 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 8, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 9, 2026
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-ClickHouse__ClickHouse that referenced this pull request Nov 9, 2026
…er's set holds NULL

DeltaLake::PartitionPruner built its partition key over removeNullable(type),
and canBePruned evaluates a NULL partition value (__HIVE_DEFAULT_PARTITION__) as
the point +inf. For a non-Nullable key column KeyCondition drops every NULL
element of a set, so has([NULL, 1], p) or p IN (NULL, 1) with
transform_null_in = 1 became the set {1}, nothing matched +inf, and the data
file of the NULL partition was skipped: its rows were silently lost. Dropping
the NULL element is exact only for a partition tuple without NULL.

The pruner now also builds the same tuple key over the table schema's own
types (Nullable for a nullable Delta field) and evaluates a partition tuple
that holds NULL against it, where NULL is an ordinary value of the key's type.
Tuples without NULL keep the existing condition, so their pruning is
unchanged. A Nullable key for every file would be correct too, but KeyCondition
declines an untyped NULL-holding set such as [NULL, 5] (Array(Nullable(UInt8)))
for a Nullable key, so has([NULL, 5], p) would stop pruning anything on tables
without a NULL partition. Accepting such sets for Nullable keys in KeyCondition
would change MergeTree as well, and would hand untyped NULL sets to the Parquet
row-group filter that still mishandles them (ClickHouse#128570, ClickHouse#128575).

Remaining loss: in a multi-column table a NULL-holding tuple is evaluated with
every nullable column Nullable, so an untyped NULL-holding integer set on
another nullable column no longer prunes that file (rows stay correct;
MergeTree with a Nullable partition key behaves the same).

The Iceberg data-file pruner had the same defect and gets the same design in
ClickHouse#130177.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants