Skip to content

Fix crash when reading Iceberg tables with ORC files and PREWHERE enabled - #101206

Merged
PedroTadim merged 21 commits into
ClickHouse:masterfrom
groeneai:fix/iceberg-orc-prewhere-crash
Jun 11, 2026
Merged

PedroTadim merged 21 commits into
ClickHouse:masterfrom
groeneai:fix/iceberg-orc-prewhere-crash

Conversation

@groeneai

@groeneai groeneai commented Mar 30, 2026 •

Copy link
Copy Markdown
Collaborator

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::getInputImpl() throws:

Logical error: 'PREWHERE passed to format that doesn't support it'

This happens because StorageObjectStorage sets supports_prewhere = true based on configuration->format (Parquet), causing the query planner to push PREWHERE conditions into format_filter_info. At read time, StorageObjectStorageSource::createReader() discovers the actual file format (ORC) via object_info->getFileFormat() but passes format_filter_info with PREWHERE info intact to the format reader.

The fix checks the actual per-file format in createReader() against FormatFactory::checkIfFormatSupportsPrewhere() before passing filter_info to the format reader. If the format doesn't support PREWHERE, prewhere_info and row_level_filter are stripped while preserving filter_actions_dag for general row-level filtering.

This was already noted as a known problem in the code comments at StorageObjectStorage.cpp:256-257:

If the table contains files in different formats, with only some of them supporting prewhere, things break.

Closes #96829

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):

Fix crash (LOGICAL_ERROR: 'PREWHERE passed to format that doesn't support it') when reading Iceberg tables containing ORC data files with PREWHERE optimization enabled.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.6.1.636
  • Backported to: 26.5.3.23, 26.4.5.33, 26.3.14.26

…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 ClickHouse#96829

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

Copy link
Copy Markdown
Collaborator Author

Pre-PR Validation Gate

a) Deterministic repro? Yes. Create an Iceberg table with ORC data files, then read via icebergLocal(..., 'Parquet', ...) with optimize_move_to_prewhere = 1, query_plan_optimize_prewhere = 1 — crashes every time on the unfixed binary.

b) Root cause explained? StorageObjectStorage sets supports_prewhere = true based on configuration->format (Parquet). The query planner pushes PREWHERE into format_filter_info. At read time, createReader() discovers the actual file is ORC via object_info->getFileFormat() but passes PREWHERE info to FormatFactory::getInput(). ORC has no registered prewhere_support_checker → getInputImpl() throws LOGICAL_ERROR.

c) Fix matches root cause? Yes — checks per-file format against FormatFactory::checkIfFormatSupportsPrewhere() in createReader(). If the format doesn't support PREWHERE, strips prewhere_info and row_level_filter while keeping filter_actions_dag.

d) New test added? Yes — 04071_iceberg_orc_prewhere_crash.sh tests both mixed-format (ORC+Parquet) and pure-ORC Iceberg tables read with Parquet config and PREWHERE.

e) Both directions demonstrated? Yes — without fix: Fatal: Logical error: 'PREWHERE passed to format that doesn't support it' (server crash). With fix: correct results (99 rows, 49 rows).

Session: cron:clickhouse-ci-task-worker:20260330-111500

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12 @kssenii — could you review this fix for the Iceberg ORC+PREWHERE crash (#96829)?

The issue is in StorageObjectStorageSource::createReader(): when an Iceberg table has mixed-format data files (Parquet + ORC), PREWHERE support is determined at the table level based on the configuration format (Parquet), but individual ORC files don't support PREWHERE, causing a server crash in FormatFactory::getInputImpl().

The fix checks each file's actual format via checkIfFormatSupportsPrewhere() before passing PREWHERE info to the format reader. @scanhex12 this is related to your PR #95476 that enabled PREWHERE for Iceberg.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Mar 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Mar 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [35291c7]

Summary: ✅


AI Review

Summary

This PR fixes mixed-format Iceberg reads where table-level PREWHERE support is enabled by a Parquet configuration but an actual file such as ORC cannot consume format-native PREWHERE. The current code strips row_level_filter and prewhere_info only for the unsupported file format, replays them after schema evolution in row-policy-then-PREWHERE order, and adds focused coverage for the exception path, row policy replay, and renamed-column schema evolution. I did not find remaining correctness issues in the changed surface.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 30, 2026
@alesapin alesapin self-assigned this Mar 30, 2026
…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]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Addressed both review points in the new commit:

1. @alesapin — code style (lambda refactoring):
Moved the per-file format check directly into the lambda that constructs filter_info. No more re-initialization of the variable outside the lambda.

2. Bot review — row_level_filter security concern:
Investigated the FormatFactory::getInputImpl check at line 444-449:

if (format_filter_info
    && (format_filter_info->prewhere_info || format_filter_info->row_level_filter)
    && (!creators.prewhere_support_checker || ...))
    throw Exception(LOGICAL_ERROR, "... passed to format that doesn't support it");

Both prewhere_info and row_level_filter trigger the same crash for non-PREWHERE formats — so simply keeping row_level_filter while stripping prewhere_info would change the crash message from "PREWHERE" to "ROW LEVEL FILTER" but not fix anything.

The correct fix is to strip both from FormatFilterInfo (to avoid the crash), then apply row_level_filter as a fallback FilterTransform in the pipeline after the format reader. The query planner puts row policies into row_level_filter when storage->supportsPrewhere() returns true (PlannerJoinTree.cpp:1012), but has no fallback FilterStep for individual files that don't support PREWHERE — so without this explicit FilterTransform, row policies would be silently skipped for ORC files in mixed-format Iceberg tables.

Session: cron:clickhouse-ci-task-worker:20260330-141500

groeneai and others added 2 commits March 31, 2026 02:22
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]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

New commit addresses two issues found during testing:

1. PREWHERE fallback for ORC files (correctness fix)
When our fix strips prewhere_info from FormatFilterInfo for ORC files, the PREWHERE filter was lost entirely — data passed through unfiltered, producing wrong results. Now we save the stripped prewhere_info and apply it as a regular FilterTransform in the pipeline after the format reader (same pattern we already use for row_level_filter).

2. Bugfix validation fix (test reliability)
The original test used WHERE c0 > 50 SETTINGS optimize_move_to_prewhere=1 to trigger PREWHERE. But the query plan optimizer cannot push PREWHERE for ObjectStorage tables because getColumnSizes() returns empty. The optimizer needs column size statistics to decide which columns go to PREWHERE — and ObjectStorage tables don't have them. So the test never actually triggered PREWHERE, and the bugfix validation couldn't reproduce the crash on the master binary.

Fix: use explicit PREWHERE c0 > 50 syntax (how it was triggered in CI stress tests) and pin input_format_parquet_use_native_reader_v3=1 (required for Parquet PREWHERE support; randomized by CI).

Verified: 20/20 passes with full randomization.

Session: cron:clickhouse-ci-task-worker:20260331-101500

@groeneai

groeneai commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator Author

@alesapin — gentle ping for re-review when you have a moment. The latest commit (v4, ef849756884) implements the refactoring exactly as you suggested: format_supports_prewhere computed once, used directly in each branch, no create-then-override.

CI is green (136/160 success, 7 failures all pre-existing trunk bugs, 17 skipped). The bugfix validation test also passes now (explicit PREWHERE syntax + fallback FilterTransform for formats without PREWHERE support).

@alexey-milovidov

Copy link
Copy Markdown
Member

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

Includes SimSIMD SVE MSan fix (PR ClickHouse#101239) and all recent master
changes as requested by @alexey-milovidov.
@groeneai

groeneai commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator Author

Done — merged latest master (includes the SimSIMD SVE MSan fix from #101239) into the branch. CI should re-run cleanly now.

@alexey-milovidov

Copy link
Copy Markdown
Member

The test 02859_replicated_db_name_zookeeper is fixed in #101952

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]>
@groeneai

groeneai commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator Author

@alesapin — fixed, pushed 15e99c72d2f.

Root cause: The test uses explicit PREWHERE on Iceberg table functions, which only works correctly through the new analyzer's FormatFilterInfo pipeline (where our per-file ORC→FilterTransform fallback operates). The two coverage-build failures are:

  1. amd_llvm_coverage, old analyzer → NOT_FOUND_COLUMN_IN_BLOCK — the old analyzer evaluates PREWHERE through a different code path that bypasses FormatFilterInfo, so our per-file format check never runs.

  2. amd_llvm_coverage, ParallelReplicas → ILLEGAL_PREWHERE — the parallel replicas coordinator validates PREWHERE support at the storage level before our per-file handling runs, rejecting it for IcebergLocal.

These two configurations only exist in coverage builds (other build types don't have old analyzer or ParallelReplicas sub-variants), which is why the test passed in all ~1600 other CI runs.

Fix:

  • Added no-parallel-replicas tag to skip in ParallelReplicas configs
  • Added enable_analyzer = 1 to query SETTINGS to force the new analyzer pipeline even in old-analyzer CI configs

@alexey-milovidov

Copy link
Copy Markdown
Member

The Can't adjust last granule error in CI is a known issue. The fix is in #101641

@PedroTadim
PedroTadim added this pull request to the merge queue Jun 11, 2026
Merged via the queue into ClickHouse:master with commit 95a5ea5 Jun 11, 2026
166 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 11, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.

TL;DR

Fix crash when reading Iceberg tables with ORC files and PREWHERE enabled

ClickGap verified: reproduced it with the script below on 26.5; tested 4 version(s) — 3 affected, 1 clean (see Affects).

Reproduction

clickhouse local --multiquery "SET allow_experimental_insert_into_iceberg=1; CREATE TABLE t (c0 Int64, c1 String) ENGINE=IcebergLocal('/tmp/ice','ORC'); INSERT INTO t SELECT number, toString(number) FROM numbers(100); INSERT INTO TABLE FUNCTION icebergLocal('/tmp/ice','Parquet','c0 Int64, c1 String') SELECT number+100, toString(number+100) FROM numbers(50); SELECT count() FROM icebergLocal('/tmp/ice','Parquet','c0 Int64, c1 String') PREWHERE c0 > 50 SETTINGS input_format_parquet_use_native_reader_v3=1, enable_analyzer=1"  -- crashes: LOGICAL_ERROR 'PREWHERE passed to format that doesn''t support it'

▶ Run on ClickHouse Fiddle

Bisect

⚠ affects matrix shows regression boundary but bisect did not converge — introducing PR is unverified

  • Bisect not performed — no regression boundary was established from the affects matrix above (the bug did not reproduce on master, or no clean baseline release was found to bound the search).

Affects

  • ✓ Fix is on master — this PR's change fixes the bug on master. Branches below still have the bug and need the backport.
  • Reproduces on: 26.5, 26.4, 26.3
  • Does NOT reproduce on: master
  • Could not test (binary unavailable): 25.8
  • Backport needed: 26.5, 26.4, 26.3

Suggested next step

The fix has landed on master; the affected release branches above still need the backport.

Component: comp-datalake
Severity: P2


ClickGap · Finding: phase_d_pr101206

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 11, 2026
robot-clickhouse added a commit that referenced this pull request Jun 11, 2026
Cherry pick #101206 to 26.3: Fix crash when reading Iceberg tables with ORC files and PREWHERE enabled
robot-clickhouse added a commit that referenced this pull request Jun 11, 2026
robot-clickhouse added a commit that referenced this pull request Jun 11, 2026
Cherry pick #101206 to 26.4: Fix crash when reading Iceberg tables with ORC files and PREWHERE enabled
robot-clickhouse added a commit that referenced this pull request Jun 11, 2026
robot-clickhouse added a commit that referenced this pull request Jun 11, 2026
Cherry pick #101206 to 26.5: Fix crash when reading Iceberg tables with ORC files and PREWHERE enabled
robot-clickhouse added a commit that referenced this pull request Jun 11, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 11, 2026
PedroTadim added a commit that referenced this pull request Jun 12, 2026
Backport #101206 to 26.5: Fix crash when reading Iceberg tables with ORC files and PREWHERE enabled
PedroTadim added a commit that referenced this pull request Jun 12, 2026
Backport #101206 to 26.4: Fix crash when reading Iceberg tables with ORC files and PREWHERE enabled
PedroTadim added a commit that referenced this pull request Jun 12, 2026
Backport #101206 to 26.3: Fix crash when reading Iceberg tables with ORC files and PREWHERE enabled
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…bles with ORC files and PREWHERE enabled
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…1206

Backport ClickHouse#101206 to 26.4: Fix crash when reading Iceberg tables with ORC files and PREWHERE enabled
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 manual approve Manual approve required to run CI 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-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.3-must-backport v26.4-must-backport v26.5-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg Logical error: 'PREWHERE passed to format that doesn't support it'

8 participants