Repository navigation
Cherry pick #101206 to 26.5: Fix crash when reading Iceberg tables with ORC files and PREWHERE enabled - #107223
Merged
Merged
Conversation
…bled When an Iceberg table has data files in mixed formats (e.g. Parquet and ORC), PREWHERE support is determined at the table level based on the configuration format (typically Parquet). If the actual file being read is in ORC format, which doesn't support PREWHERE, the FormatFactory throws a LOGICAL_ERROR: "PREWHERE passed to format that doesn't support it". Fix by checking the actual per-file format in createReader() before passing format_filter_info to the FormatFactory. If the file's format doesn't support PREWHERE, strip prewhere_info and row_level_filter while preserving filter_actions_dag for general row filtering. Closes #96829 Co-Authored-By: Claude Opus 4.6 <[email protected]>
…urity Per @alesapin's review: moved the per-file format PREWHERE check directly into the lambda that constructs filter_info, eliminating the separate block that re-initialized the variable. Per bot review: when stripping PREWHERE-related fields for formats that don't support it, the row_level_filter is now preserved and applied as a fallback FilterTransform in the pipeline. FormatFactory::getInputImpl checks both prewhere_info and row_level_filter against format support (line 444-449), so both must be stripped from FormatFilterInfo. But the query planner only puts row policies into row_level_filter when storage->supportsPrewhere() is true (PlannerJoinTree.cpp:1012), with no fallback FilterStep — so without this explicit FilterTransform, row policies would be silently skipped for non-PREWHERE files in mixed-format Iceberg tables. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Refactored the lambda to compute format_supports_prewhere once and use it directly in each branch, eliminating the create-then-override pattern. Each branch now directly produces the final FormatFilterInfo. Co-Authored-By: Claude Opus 4.6 <[email protected]>
When reading mixed-format Iceberg tables (Parquet + ORC), our fix strips prewhere_info from FormatFilterInfo for ORC files to prevent a crash. But the stripped PREWHERE filter was not being applied at all, causing wrong results when explicit PREWHERE syntax was used. Fix: save the stripped prewhere_info and apply it as a regular FilterTransform in the pipeline after the format reader, similar to how we handle stripped row_level_filter. Also fix the regression test to use explicit PREWHERE syntax (the query plan optimizer cannot push PREWHERE for ObjectStorage tables because getColumnSizes() returns empty). Pin input_format_parquet_use_native_reader_v3=1 since PREWHERE support requires the native Parquet reader v3. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Includes SimSIMD SVE MSan fix (PR #101239) and all recent master changes as requested by @alexey-milovidov.
The test uses explicit PREWHERE on Iceberg tables with mixed ORC/Parquet data files. This fails in two coverage-build CI configurations: 1. amd_llvm_coverage, old analyzer: NOT_FOUND_COLUMN_IN_BLOCK because the old analyzer evaluates PREWHERE through a different code path that doesn't go through FormatFilterInfo (where our per-file format check strips PREWHERE for ORC files). 2. amd_llvm_coverage, ParallelReplicas: ILLEGAL_PREWHERE because the parallel replicas coordinator validates PREWHERE support before our per-file handling runs, and rejects it for IcebergLocal storage. Fix: - Add no-parallel-replicas tag to skip in ParallelReplicas configs - Add enable_analyzer=1 to query SETTINGS to force the new analyzer pipeline where our FormatFilterInfo-based fix operates correctly Co-Authored-By: Claude Opus 4.6 <[email protected]>
… fallback
Address two correctness bugs in the post-read FilterTransform fallback path
used when an Iceberg table is configured for a format that supports PREWHERE
(e.g. Parquet) but contains data files in a format that does not (e.g. ORC).
1. Transform ordering: apply row-level filter before PREWHERE.
The previous order applied `stripped_prewhere_info` first and
`stripped_row_level_filter` second. PREWHERE actions output only the
synthetic filter column plus the columns needed downstream — `updateHeader`
drops the PREWHERE input column from the block. If a row policy referenced
that same column (e.g. policy `c0 > 5`, query `SELECT c1 ... PREWHERE c0 > N`)
it could not be evaluated, because the policy ran after PREWHERE had
already removed `c0`.
The new order matches the canonical filter pipeline used everywhere else:
`SourceStepWithFilter::applyPrewhereActions`,
`MergeTreeSelectProcessor::getPrewhereActions`, and
`Parquet::Reader::initializePrewhere` all apply row-level filter first,
PREWHERE second. Aligning the fallback path closes the inconsistency.
2. Column propagation: re-add stripped filter inputs to the reader header.
`read_from_format_info.format_header` was already adjusted by
`updateFormatPrewhereInfo` to reflect the post-PREWHERE schema before the
source was created — columns referenced only by PREWHERE were treated as
"consumed" by the format reader. When the actual file format does not
support PREWHERE and we apply the filter as a transform after the reader,
those input columns must still be present in the block. We now augment
`initial_header` with any input column of the stripped DAGs that is
missing from `format_header`.
This bug was masked for `count()` queries because they go through the
`need_only_count` path, which bypasses regular column reads. Any query
that actually projected data through the fallback path (e.g.
`SELECT c1 FROM t PREWHERE c0 > N`, where `c0` is not in the SELECT
list) failed with `NOT_FOUND_COLUMN_IN_BLOCK: Not found column c0`.
Tests:
- 04071 (existing): still passes; covers the `need_only_count` path.
- 04146 (new): regression test exercising both bugs simultaneously —
a row policy on `c0` plus a PREWHERE on `c0` plus a SELECT that
does not reference `c0`. Without the column-propagation fix the
sum query throws; without the ordering swap the row policy throws.
Three queries cover count(), aggregate-over-projected-column, and
a PREWHERE that overlaps but is wider than the policy.
Address bot's third review concern on PR #101206: in the schema-changed branch (Iceberg RENAME COLUMN / type evolution / NULL-default columns), the fallback FilterTransforms for stripped row-level filter and PREWHERE were running BEFORE the schema_transform ExpressionTransform. Filter expressions reference query-side column names while the format reader emits file-side names, so the fallback filter throws NOT_FOUND_COLUMN_IN_BLOCK when a renamed column appears in a row policy or PREWHERE (e.g. policy on renamed_c0 against ORC files written under the old name c0). Fix: 1. Move the two stripped FilterTransform constructions in StorageObjectStorageSource::createReader to AFTER the schema_transform ExpressionTransform. Filters now evaluate against the same query-side column names the planner produced, matching the canonical pipeline order in SourceStepWithFilter::applyPrewhereActions, MergeTreeSelectProcessor::getPrewhereActions, and Parquet::Reader::initializePrewhere. 2. When the data lake provides a schema_transform that goes through removeUnusedActions, augment the kept-name list with input columns referenced by the stripped filters. Otherwise requested_columns (which is post-PREWHERE and excludes filter inputs) would prune the columns the fallback filters need to evaluate. Iceberg's getSchemaTransformer already returns the full new-schema DAG without removeUnusedActions, so it carries filter inputs through automatically — but the Delta Lake metadata path applies removeUnusedActions, and (2) keeps that path correct if it ever co-occurs with a stripped-PREWHERE ORC file. Regression test 04147_iceberg_orc_schema_evolution_row_policy.sh: creates an Iceberg table at Parquet format, writes ORC data files through the icebergLocal table function, runs RENAME COLUMN to bump the schema, sets up a row policy and PREWHERE on the renamed column, and verifies that the queries return correct results. Without this change the test fails with NOT_FOUND_COLUMN_IN_BLOCK. CI Fix or Improvement (changelog entry is not required) Co-Authored-By: Claude Opus 4.7 <[email protected]>
…ests All three tests (04071, 04146, 04147) query data via the `icebergLocal` table function, which is a local table function with nothing to distribute across replicas. The `no-parallel-replicas` tag was originally added on April 8 as belt-and-suspenders alongside `SETTINGS enable_analyzer = 1`, but the actual root cause of the April 7 `ILLEGAL_PREWHERE` failures on the `amd_llvm_coverage, ParallelReplicas` config was the OLD analyzer code path that bypasses `FormatFilterInfo` — pinning `enable_analyzer = 1` in `SETTINGS` already fixes that. For `icebergLocal`, parallel replicas randomization (`enable_parallel_replicas`, `parallel_replicas_for_non_replicated_merge_tree`) has no effect because there is no distributed plan to build, so the tag is redundant. Per `tests/queries` style guidance, `no-*` tags should not be added unless strictly necessary. Addresses @PedroTadim review on PR #101206.
Reverts the test-only change from 44de78e. CI confirmed that removing the `no-parallel-replicas` tag regressed `Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel)`: `04071_iceberg_orc_prewhere_crash` failed 3/3 reruns with Code: 182. DB::Exception: Storage IcebergLocal (table _table_function.icebergLocal) does not support PREWHERE. (ILLEGAL_PREWHERE) thrown from `CollectTableExpressionData.cpp:301` during query analysis. Root cause (separate engine bug): `TableFunctionObjectStorage::executeImpl` wraps the storage in `StorageObjectStorageCluster` whenever `parallel_replicas_for_cluster_engines = 1` (default) and `cluster_for_parallel_replicas` is set. The cluster wrapper does NOT override `supportsPrewhere` and therefore inherits the default `false` from `IStorage`. The analyzer's `CollectPrewhereTableExpressionVisitor` then rejects any explicit `PREWHERE` against the cluster storage. The cluster-wrapper bug is unrelated to this PR's scope (which fixes the non-cluster mixed-format Iceberg path). A proper delegation override on `StorageObjectStorageCluster::supportsPrewhere` / `canMoveConditionsToPrewhere` / `supportedPrewhereColumns` should be done in a follow-up PR with separate review. Failing CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101206&sha=44de78e89944d2f279696616d2e8abd06902680a&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 PR: #101206
…where-crash-rebased
The functional-test result parser recognized two server-death signs from clickhouse-test: `Server died, terminating all processes` (per-test) and `Server does not respond to health check` (per-test, after liveness retry). It did not recognize `Hung check failed: server is not responding`, which is printed by the periodic hung check loop in `tests/clickhouse-test` when the server stops responding mid-run. The hung check then terminates all worker processes with SIGTERM, so no individual test reaches a `FAIL` status either. In bugfix validation that combination produced "Failed to reproduce the bug" even when the master baseline binary had clearly crashed (a `core.QueryPipelineEx.*` core dump was produced in the artifacts). Recognizing the third sign lets the existing `server_died` branch run, which appends a synthetic `Server died` FAIL result; bugfix validation then inverts that FAIL to OK and correctly concludes the bug was reproduced. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100146&sha=433142dee5879c98705136b654293365ca6a0cf6&name_0=PR&name_1=Bugfix%20validation%20%28functional%20tests%29 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…where-crash Resolves @PedroTadim's merge-conflict request on PR #101206. Single conflict in `ci/jobs/scripts/functional_tests_results.py`. Master refactored server-died detection (commits fc45ec9, bfb9a67, f6c754b) from log-string matching to using `STOP_TESTING_EXIT_CODE` from `clickhouse-test`. The cherry-pick of `SERVER_DIED_SIGN3` from commit ff56c4c (added 2026-05-19 to fix Bugfix validation false negatives on hung-check server crashes) is now obsolete — the new exit-code mechanism covers the same case more cleanly. Took master's version. `src/Storages/ObjectStorage/StorageObjectStorageSource.cpp` auto-merged cleanly with master's additions (`#include FormatParserSharedResources.h`, new `onFinish` method). All three regression tests (04071, 04146, 04147) and the PR fix logic (stripped `FilterTransform`s applied after `schema_transform`, in row-level-filter-then-PREWHERE order) preserved. PR: #101206 Issue: #96829
Fix crash when reading Iceberg tables with ORC files and PREWHERE enabled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #101206
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job