Skip to content

Keep the NULL partition in Delta Lake partition pruning when the filter's set holds NULL - #130192

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-delta-lake-partition-pruning-null-in-set
Nov 9, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-delta-lake-partition-pruning-null-in-set

Conversation

@groeneai

@groeneai groeneai commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #130177

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 Delta Lake partition pruning skipping the data files of a NULL partition when the filter's set holds NULL, such as has([NULL, 1], p) or p IN (NULL, 1) with transform_null_in = 1.

Description

On 26.10.2.103, SELECT arraySort(groupArray(v)) FROM deltaLakeLocal('<dir>/t') WHERE has([NULL, 1], p) over a Spark-written Delta table partitioned by a nullable p with a NULL partition (p=__HIVE_DEFAULT_PARTITION__) returns [] instead of [2]. 26.3.60.2, 26.8.34.13 and 26.9.25.15 are the same.

DeltaLake::PartitionPruner builds its key over the non-Nullable column types, so KeyCondition drops the NULL element of the set, while canBePruned evaluates a NULL partition value as +inf. Nothing in the set matches it, and the file is skipped.

The pruner now evaluates a partition tuple that holds NULL against the same key built over the table schema's own types (Nullable for a nullable field). 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], p) on tables without a NULL partition, which the test checks. One narrow loss remains: in a multi-column table, a file whose tuple holds NULL is no longer pruned by an untyped NULL-holding integer set on another nullable column (rows stay correct; MergeTree with a Nullable partition key behaves the same).

#130177 fixes the same defect in the Iceberg data-file pruner with the same design. The Paimon partition pruner strips Nullable the same way; it is not changed here.

Validation: the new test 05576_delta_lake_partition_pruning_null_in_set fails on master and passes with the fix (50 randomized runs); the Delta Lake stateless tests and the test_storage_delta partition-pruning integration tests pass.


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

Version info

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

groeneai and others added 2 commits November 8, 2026 17:36
…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]>
Condense the key-choice comment in 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 (2 nits, none blocking).

# Sev Finding Verdict Evidence / action
1 💡 nit In a multi-column table, a file whose tuple holds NULL is evaluated with every nullable column Nullable, so an untyped NULL-holding integer set on another column no longer prunes it Noted, not blocking Rows stay correct (has([NULL, 5], b): [3] with and without the fix; 2 -> 1 files pruned). Avoiding it needs one condition per NULL pattern; MergeTree with a Nullable partition key does not prune that shape either. Disclosed in the description.
2 💡 nit No subquery-set arm in the test Disagree Measured: p IN (SELECT 5) gives [1] with 3 files pruned with and without the fix; the regression arms of the test already fail on master.

@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. The new test against a master build fails the same 7 arms on every run (has([NULL, 1], p) returns [] with 4 of 4 files pruned); nothing randomized is in the path.
b Root cause explained? The partition key is built over removeNullable(type), so KeyCondition drops the NULL element of a set for that key, while a NULL partition value is evaluated as +inf. Nothing in the set matches +inf, so the NULL partition's file is skipped.
c Fix matches root cause? Yes. A tuple holding NULL is evaluated against the same key over the schema's own (Nullable) types, where NULL is an ordinary value; tuples without NULL keep the existing condition.
d Test intent preserved / new tests added? New 05576_delta_lake_partition_pruning_null_in_set: 7 regression arms plus 9 sentinels for pruning that must stay (a table without a NULL partition, =, <, IS [NOT] NULL, a NULL-free set, ifNull).
e Both directions demonstrated? Fails on master, passes with the fix. Forcing the old key reproduces master's output exactly; forcing the Nullable key for every file keeps rows right but loses pruning (has([NULL, 5], p) on a table without a NULL partition prunes 0 files instead of 2).
f Fix is general across code paths? Every Delta Lake entry point (table functions, deltaLakeCluster, the engine, the database engine) goes through this pruner, its only caller. Iceberg's data-file pruner is fixed the same way in #130177. Paimon's pruner shares the convention and is not changed here.
g Fix generalizes across inputs (params/datatypes/wrappers)? Tested: Int64, String, two partition columns, typed Array(Nullable(Int64)), IN with transform_null_in = 1, NOT has. Also checked Date32, DateTime64(6), Decimal(10, 2), Bool and Spark-written tables. Residual: a multi-column NULL tuple with an untyped NULL-holding integer set on another nullable column prunes one file fewer; rows are correct.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, format or stored state changes; only pruning decisions for tuples holding NULL change.
i Invariants and contracts preserved? A file is pruned only when no row can match: unchanged for tuples without NULL, exact under the Nullable key otherwise. Both conditions are built together in the constructor and only read by the concurrent const canBePruned.

Session id: cron:clickhouse-impl-self-slot-57:20261108-165500

@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

cc @kssenii @SmitaRKulkarni, could you review this and add the can be tested label so CI runs? The Delta Lake partition pruner now evaluates a partition tuple that holds NULL against the same key built over the schema's Nullable types, so has([NULL, 1], p) no longer skips the NULL partition's files; it is the Delta Lake counterpart of #130177.

@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1c4486b]

Summary: ✅


AI Review

Summary

PR #130192 fixes Delta Lake partition pruning discarding matching NULL partitions by selecting a schema-typed key and condition for tuples containing NULL. Tuples without NULL retain the existing condition. Reviewed the current code and full diff at 1c4486beceb4fdb5d91865041cd5599045c5da74, the calling iterator, set and range evaluation, regression coverage, and all prior discussion. No actionable findings.

Missing context / blind spots
  • ⚠️ No local ClickHouse binary or build was available, so the regression test was not executed independently. The PR reports successful before/after validation and 50 randomized runs. The current CI workflow is running, with targeted stateless tests and functional bugfix validation pending. Fast test passed but excludes this test. A completed Delta-enabled run of 05576_delta_lake_partition_pruning_null_in_set would close this validation gap.
Final Verdict

✅ Approve. No code changes requested. Independent 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 1c4486bec with master 1b8054738 (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

8 translation units recompiled, 22 s compile time in total, 8 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 0ff7247 Nov 9, 2026
373 of 375 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 9, 2026
@arsenmuk arsenmuk added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Nov 11, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Nov 11, 2026
alexey-milovidov pushed a commit that referenced this pull request Nov 12, 2026
… can run

26.3's KeyDescription::getKeyFromAST takes no `virtuals` argument (#102827 is
not on 26.3), so drop the `{}` the cherry-pick carried.

The test built its Delta tables with INSERT INTO FUNCTION deltaLakeLocal under
allow_delta_lake_writes. On 26.3 that setting is still called
allow_experimental_delta_lake_writes, and a partitioned INSERT of a NULL value
fails with NOT_IMPLEMENTED (#111793 is not on 26.3). Write the same tables by
hand instead, as 26.3's 05237 test does: Parquet data files through file() and
one add action per file, a NULL partition value committed as a JSON null under
__HIVE_DEFAULT_PARTITION__.

Two cases fail on 26.3 with and without this change, so they are dropped:
`ifNull(p, 0) IN (0)` prunes the NULL partition (a MergeTree table partitioned
by the same Nullable column returns the same wrong rows on 26.3), and
`has([NULL, 'a'], s)` throws CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN (#115647 is
not on 26.3). On 26.3 the fix keeps the NULL partition's file for
`has([5, 7], p)`, so that case prunes 1 file instead of 2 (rows unchanged):
26.3 builds no set index for a UInt8 array over a Nullable(Int64) key; 26.3's
MergeTree partition pruning does not use that predicate on a Nullable key either.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
clickhouse-gh Bot added a commit that referenced this pull request Nov 12, 2026
Backport #130192 to 26.8: Keep the `NULL` partition in Delta Lake partition pruning when the filter's set holds `NULL`
clickhouse-gh Bot added a commit that referenced this pull request Nov 12, 2026
Backport #130192 to 26.10: Keep the `NULL` partition in Delta Lake partition pruning when the filter's set holds `NULL`
clickhouse-gh Bot added a commit that referenced this pull request Nov 12, 2026
Backport #130192 to 26.9: Keep the `NULL` partition in Delta Lake partition pruning when the filter's set holds `NULL`
leshikus pushed a commit that referenced this pull request Nov 13, 2026
…tition pruning when the filter's set holds `NULL`
leshikus pushed a commit that referenced this pull request Nov 13, 2026
…tition pruning when the filter's set holds `NULL`
leshikus pushed a commit that referenced this pull request Nov 13, 2026
…rtition pruning when the filter's set holds `NULL`
alexey-milovidov added a commit that referenced this pull request Nov 14, 2026
The `26.3` branch history was rewritten, so the previously merged `26.3`
commits are no longer its ancestors. Conflicts in `src/Core/Field.cpp` and
`src/Interpreters/InterpreterCreateQuery.cpp` (files this PR does not touch)
are resolved by taking the `26.3` version; the result differs from `26.3`
only in this backport's four files.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Nov 15, 2026
…t-130192

Backport #130192 to 26.3: Keep the `NULL` partition in Delta Lake partition pruning when the filter's set holds `NULL`
@clickhouse-gh clickhouse-gh Bot added comp-delta-lake Delta Lake tables: reading Delta metadata through delta-kernel-rs (table snapshots, schema and ty... 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-delta-lake Delta Lake tables: reading Delta metadata through delta-kernel-rs (table snapshots, schema and ty... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

5 participants