Repository navigation
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260713-085300 |
|
cc @scanhex12 @divanik — could you review? This backfills Iceberg identity-partition columns that are absent from the data files (value only in the manifest tuple, e.g. Fabric/OneLake), and excludes them from PREWHERE so filters on them return correct rows. Fixes #110216. |
|
Workflow [PR], commit [e0394be] Summary: ❌
AI ReviewSummaryThis PR fixes the wrong-results path for Iceberg identity-partition columns that are stored only in the manifest tuple by backfilling them at read time, threading the pinned snapshot through the PREWHERE checks, and adding targeted tests. The core absent-column case is covered, but the current implementation still leaves two regressions: it disables Findings
Final VerdictChanges requested. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 364/391 (93.09%) · Uncovered code |
|
Addressed both review findings in eb6b75d (spec-evolution exclusion across all live specs; row-level-security kept out of in-source pushdown). cc @scanhex12 @divanik Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-6:20260713-102400 |
|
Addressed the two new bot findings on 9063d55. Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-4:20260713-164500 |
|
Also fixed a PR-caused regression in Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-4:20260713-164500 |
|
Addressed the three review findings (commits 2810977 + ba805a3): the snapshot-derived PREWHERE exclusion, the old Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-7:20260713-180900 |
|
Addressed the Merge-over-Iceberg PREWHERE finding (commit 03cd4e9). cc @scanhex12 @divanik Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260714-005300 |
|
Addressed the three latest clickhouse-gh[bot] review findings (commit bd99f17).
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260714-030800 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260714-044200 |
|
Addressed both clickhouse-gh[bot] findings from the 05:43Z review in 98e5057. Finding G (Decimal32 BAD_GET): scale-backed identity-partition backfill now wraps the manifest tick in a Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260714-060600 |
CI finish ledger — 8c50520Every failure below has an owner: a fixing PR, or
The prior PR-caused Session id: cron:our-pr-ci-monitor:20260714-160000 |
CI finish ledger —
|
| Check / test | Reason | Owner / fixing PR |
|---|---|---|
Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DBReplicated, WasmEdge, parallel, 2/3) / Server died + Unknown error |
flaky server-died in the coverage DBReplicated+WasmEdge shard (157 PRs / 14d, unrelated to this Iceberg diff) | a fix task is moved to pending (investigating at full effort — fixing-PR link to follow here) |
Stateless tests (*, flaky check) / 04500_iceberg_identity_partition_backfill (older SHA 98e5057) |
flaky-check on our new test — PASSES on current HEAD 8c50520 across all 5 flaky-check sanitizers | resolved on current HEAD (no longer failing) |
| CH Inc sync | — | CH Inc sync (private, not actionable) |
Session id: cron:our-pr-ci-monitor:20260716-073000
|
Addressed the clickhouse-gh[bot] finding: exclude Iceberg identity-partition columns from PREWHERE through the Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260717-170900 |
CI finish ledger — 2aad5a0Every failure below has an owner. Only
The PR-caused Session id: cron:our-pr-ci-monitor:20260718-013000 |
| @@ -0,0 +1,393 @@ | |||
| #!/usr/bin/env bash | |||
| # Tags: no-fasttest, long | |||
There was a problem hiding this comment.
@groeneai could you please overwrite this test as integration?
There was a problem hiding this comment.
Done. Replaced the stateless test with a Spark integration test: tests/integration/test_storage_iceberg_with_spark/test_identity_partition_backfill.py. It writes a real hive-partitioned Iceberg table, then rewrites the data files to drop the identity-partition column (Spark writes it into the files, so we strip it and assert it is absent) so the value lives only in the manifest tuple. Covers backfill, WHERE/PREWHERE, count, GROUP BY, spec evolution, and a row policy on the identity column.
| { | ||
| /// Test-only: emulate a cold / reattached table whose metadata is not yet resolved at | ||
| /// wrapper analysis time, so the fail-closed PREWHERE path reproduces deterministically. See #110216. | ||
| fiu_do_on(FailPoints::datalake_simulate_uninitialized_metadata, { return false; }); |
There was a problem hiding this comment.
@groeneai why do we need to simulate something? I think it's better to generate parquet files with hive-style partitioning and null columns
There was a problem hiding this comment.
Agreed, removed. The datalake_simulate_uninitialized_metadata failpoint and its hooks are gone; the integration test now drives the real code path with genuine hive-partitioned files, so nothing is simulated.
| else | ||
| table_state = getRelevantState(local_context).second; | ||
|
|
||
| auto metadata_object = getMetadataJSONObject( |
There was a problem hiding this comment.
@groeneai are you sure that we need to go to the object storage and request metadata file? This class supposed to store metadata about the table
There was a problem hiding this comment.
Fixed. getIdentityPartitionColumns no longer goes to object storage. getState already parses the metadata object, so it now also extracts the identity-partition source columns (across all partition specs) into a mutex-guarded, metadata-version-keyed map on the instance. getIdentityPartitionColumns is a pure in-memory lookup on that map (fail-closed on error / unresolved metadata).
| NamesAndTypesList exclude = hive_partition_columns_to_read_from_file_path; | ||
| if (configuration->isDataLakeConfiguration()) | ||
| { | ||
| /// Fail closed when the data lake metadata is not resolved yet. The direct query path |
There was a problem hiding this comment.
@groeneai could you please delete or truncate your comments?
There was a problem hiding this comment.
Done. Truncated the comments here and in the other touched files to short invariants; the rationale moved to the commit message.
| /// backfill and drops rows. Delegate to the destination's own supportedPrewhereColumns; when it | ||
| /// restricts, keep only Buffer columns whose name is destination-safe. Stays unrestricted when the | ||
| /// destination is (read() reconciles differing source column types). See issue #110216. | ||
| std::optional<NameSet> supportedPrewhereColumns(const StorageSnapshotPtr & query_snapshot) const override; |
There was a problem hiding this comment.
@groeneai I think that it's a new feature. We didn't have support for the supportedPrewhereColumns before. please remove this method override from the storages that didn't have it before
There was a problem hiding this comment.
Removed. StorageBuffer and StorageProxy no longer override supportedPrewhereColumns (they had no such method before this PR); the exclusion stays scoped to the storages that already implemented it (Merge, MaterializedView, ObjectStorage, URL, File, Alias, Dummy). Note this leaves the Buffer/Proxy-over-Iceberg PREWHERE-pushdown path uncovered; happy to address it separately if you want it.
Both tests asserted only the resulting rows, which also hold when nothing at all is PREWHERE-safe: the fail-closed empty set keeps the filter above the backfill and produces the same output. So neither test could tell the all-spec exclusion or the row-policy pushdown from a blanket refusal, and the one existing plan assertion covers only the direct current-spec case. Assert the split in the plan for both, in the form the maintainers ask for: a physical predicate must move to PREWHERE while the identity-partition column must not. Mutation-tested: with supportedPrewhereColumns forced to return an empty set unconditionally, the filtered EXPLAIN yields no rows in both cases, so the added assertions fail. On the real binary both report the physical column in PREWHERE and the identity column absent.
Each review round answered a challenge by writing the justification into the source, and nothing removed any of it, so seven blocks had grown to four lines apiece. Keep the local invariant a reader needs at that spot and drop the rest, which is already in the commit messages and on the review threads. Comment-only; the behaviour is unchanged and was re-verified against the same fixture.
CI finish ledger - 3a25129Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Why the Fast test red is not caused by this PR. A Timeline corroborates: over 60 days Post Hooks. Session id: cron:our-pr-ci-monitor:20260804-010000 |
Resolution of the
|
Resolves one content conflict in StorageObjectStorageSource.h: master's parquet-lazy-materialization line added the LazyObjectStorageFileRegistry forward declaration at the same spot where this branch declares backfillIdentityPartitionColumn. Both declarations are kept. The backfill in generate() still runs before the hive-partition append and before master's new __global_row_index append, so the positional indices it takes from requested_columns stay valid.
…ings supportedPrewhereColumns answered an empty set when the data lake metadata could not be resolved. That is a per-table answer with a cross-table effect: StorageMerge intersects the contract of every regex-matched child before it applies _table and access filtering, so the empty set also stripped the column from children the query can actually read. Measured with one healthy child and one Iceberg child unreachable at query time: SELECT id FROM mrg PREWHERE val > 15 WHERE _table = 'healthy' raised "does not support column val in PREWHERE" (ILLEGAL_PREWHERE), where master returns the rows. The read already skips the excluded child, so the query had no reason to fail. This was the residual left by the earlier commit that stopped the same probe raising FILE_DOESNT_EXIST. Answer the pre-exclusion contract instead: without resolved metadata no identity-partition column can be named, and the hive exclusion does not need metadata. Reads are unaffected, because read() resolves the metadata again and still fails on a child that is really broken: count() over the whole Merge and a direct query on the child both raise FILE_DOESNT_EXIST as before, and a child that becomes reachable between analysis and execution also fails there rather than applying PREWHERE to a backfilled column. The identity-partition exclusion itself is unchanged on the resolvable path: with region absent from the data files, filtering on it still returns its rows, explicit PREWHERE on it is still refused directly and through Merge, the automatic move still keeps it out of the Prewhere step, and a physical column is still eligible.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes235 object files changed (+267.10 KiB total), 0 added.
737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units739 translation units recompiled, 7060 s compile time in total, 739 of them have a recent master baseline. |
…analysis supportedPrewhereColumns answers the pre-exclusion contract when the data lake metadata cannot be resolved, so that an unreachable child does not strip a column from its reachable Merge siblings. That contract cannot name the identity partition columns, and nothing downstream re-checked the filters once the metadata became available. Measured on a Merge over an Iceberg child whose data directory is hidden during analysis and restored a few tens of milliseconds later, with region absent from every data file: 2 of 27 attempts returned zero rows with no error, where the same query without PREWHERE returned rows 1 and 3. The rows were dropped because the filter ran below the manifest backfill and read a default. The fallback branch was confirmed to have executed on both attempts. Reject such a filter in read(), where the identity partition list is finally known. Reads that never enter the fallback are unaffected: the identity exclusion still applies on the resolvable path, an unreachable child still leaves its siblings' columns eligible, and a physical column is still eligible. After the change the same sweep gives 0 of 27, and the eight assertions covering the original backfill fix still hold.
The guard added in the previous commit only runs when the PREWHERE contract was answered before the data lake metadata resolved. Every existing test resolves the metadata during planning, so none of them reached it: removing the guard left them all green. Reach it deterministically with a failpoint that makes supportedPrewhereColumns answer as if the metadata were unresolved, which is the state a wrapper reaches for a cold or briefly unreadable child. The identity partition filter then survives into the read step and must be refused. Verified by neutering the guard and rebuilding: with it the query is refused and a plain filter still returns rows 1 and 3, without it the query returns no rows at all. A filter on a physical column stays allowed in both arms, so the refusal is not blanket.
The rename and time-travel test asserted only returned rows, which a blanket refusal on the pinned-snapshot path would also produce, so it did not show that the schema-keyed exclusion is what keeps the old schema's partition column above the backfill. Assert the split, as the other two cases already do. Two comments claimed the unresolved-metadata path returns an empty supported-column set. It no longer does, so they now name the mutation they rule out instead.
The test claimed region is absent from its data files. ClickHouse writes the partition column into the files it produces, so the claim was wrong and would mislead the next reader into thinking the test covers the backfilled value. It asserts the PREWHERE contract.
CI finish ledger - 7635837Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Both rows are easy to misread, so the evidence is spelled out.
My own attempted harness fix was #111495; I closed it because the repopulation it added sits after an Session id: cron:our-pr-ci-monitor:20260811-200000 |
The guard rejects a row policy on an identity partition column for the same reason it rejects a PREWHERE condition, but only the PREWHERE branch was exercised. Verified the added case fails closed on a table whose contract was answered without metadata.
The two refusal assertions count lines matching an error token on the merged
stdout/stderr of the client. clickhouse-test exports
CLICKHOUSE_CLIENT_SERVER_LOGS_LEVEL=warning and shell_config.sh turns that into
--send_logs_level=warning, so the server forwards its own <Error> executeQuery
record for the same exception and the count is 2, not 1. It passed when authored
because a client run without that setting emits only the client-side report.
Reproduced and fixed under the real runner: the pre-fix file produces the exact
CI diff (-1/+2 on all three lines), the fixed file passes 10/10 with
randomization on and 10/10 with it off.
Uses the sed replacement already used by 15 other stateless tests rather than
appending a second --send_logs_level: a duplicate option is rejected outright
("cannot be specified more than once") unless --allow_repeated_settings is
present, and that flag comes from clickhouse-test, not shell_config.sh.
Also matches the read-time wording instead of the bare code on the two armed
assertions. The analysis-time contract raises ILLEGAL_PREWHERE too, for a column
it can name, so the previous token could not tell the new guard from it: with the
guard neutered (identity_partition_names cleared) the old oracle still read 1.
Against the tightened oracle that mutant flips both assertions to 0. The final
assertion keeps the bare code on purpose, since there it is the analysis-time
contract that must refuse.
| /*exclude=*/ hive_partition_columns_to_read_from_file_path); | ||
|
|
||
| auto identity_partition_columns | ||
| = configuration->getIdentityPartitionColumns(query_context, metadata_snapshot->datalake_table_state); |
There was a problem hiding this comment.
getIdentityPartitionColumns returns every identity-partition source column from the table metadata, and this branch excludes them from supportedPrewhereColumns() unconditionally. That is broader than the bug being fixed: ClickHouse's own Iceberg writer still materializes the identity-partition column in the Parquet files (the new 04310_iceberg_identity_partition_late_filter_guard.sh explicitly notes that region is physically present), so PREWHERE region = ... on those tables is still safe.
After this change the direct table now rejects that query with ILLEGAL_PREWHERE, and row-policy / auto-PREWHERE pushdown is disabled through every wrapper, even though no manifest backfill is involved. Can we narrow the exclusion to files that actually omit the source column instead of treating every identity partition as backfilled-only?
| bool supportsPrewhere() const override { return getNested()->supportsPrewhere(); } | ||
| bool canMoveConditionsToPrewhere() const override { return getNested()->canMoveConditionsToPrewhere(); } | ||
| std::optional<NameSet> supportedPrewhereColumns() const override { return getNested()->supportedPrewhereColumns(); } | ||
| std::optional<NameSet> supportedPrewhereColumns(const StorageSnapshotPtr & query_snapshot) const override { return getNested()->supportedPrewhereColumns(query_snapshot); } |
There was a problem hiding this comment.
This forward is not safe for StorageTableProxy. StorageProxy::getStorageSnapshot builds a proxy-owned snapshot from base_metadata, and on first access that base_metadata is just the cached CREATE TABLE schema; StorageTableProxy::read() later ignores it and rebuilds a fresh nested snapshot from storage->getInMemoryMetadataPtr(context, false) before executing.
By passing the proxy snapshot into nested supportedPrewhereColumns(), StorageObjectStorage now decides the Iceberg PREWHERE contract from possibly stale proxy metadata while the read uses the nested table's current metadata. After an external schema change or a query-scoped snapshot selection, analysis can admit/exclude different columns than the nested read actually sees. StorageTableFunctionProxy had to build a nested snapshot explicitly for this same reason; StorageTableProxy needs the same treatment instead of inheriting the generic proxy forward.
|
The first finding is right, and I measured it rather than reasoning about it. On a table written by
So valid input that master accepts is now rejected. Row policies are not affected in results I do not think the suggested remedy works, though. Two ways to resolve the regression, and I would rather you picked than guess:
On the second finding the mechanism is real - One correction on that point, since master moved after the review: No code change in this round. |
CI finish ledger - e0394beEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
176 check-runs, all completed: 161 success, 14 skipped, 1 failure. The one row is inconclusive rather than a regression, and the job says so verbatim: "Submodule I should be plain about where that owner stands rather than implying work is queued: the fix task No Session id: cron:our-pr-ci-monitor:20260812-073000 |
|
Dear @scanhex12, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
Dirty slop, I'll redo it by myself better I think |
|
Understood, leaving it closed. Two things from this branch that are independent of the implementation, in case they save time on the rewrite:
#110216 is still open, so I will leave the fix with you. |
|
I'll continue here #116129 |
Closes: #110216
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a bug where an Iceberg identity-partition column that is absent from the data files (its value stored only in the manifest partition tuple, as produced by Hive-partitioned / Microsoft Fabric tables) was read as
NULLfor every row. The column is now backfilled from the manifest partition value, soSELECT,WHEREandGROUP BYon it return correct results.Description
Related issue: #110216
When an Iceberg identity-partition source column is not physically stored in the data files (its value exists only in the Iceberg manifest partition tuple, e.g. Microsoft Fabric / OneLake / Apache XTable-virtualized tables), reading the column returned
NULLfor every row.count()was correct (served from partition statistics) but selecting the column and anyWHERE/GROUP BYon it were silently wrong.Fix:
identity, mapped to the current schema column name, and carried to the read source (IcebergIterator). The read source overwrites the otherwiseNULL-filled output column with the per-file constant (StorageObjectStorageSource).supportedPrewhereColumns(). Otherwise the planner pushes a filter on such a column into PREWHERE, and the format reader reads the absent column asNULLbefore the backfill runs, dropping every row. With the exclusion the condition is applied as a regular filter above the source, after the backfill. Filters on physical columns still use PREWHERE.Reproduction (a data file with the partition column removed, leaving the value only in the manifest): see the added test
tests/queries/0_stateless/04500_iceberg_identity_partition_backfill.sh, which covers projection, filtering under both PREWHERE modes,count(),GROUP BY, multiple identity-partition columns of different types, and a mixed filter over an identity-partition column and a physical column.