Repository navigation
Fix LOGICAL_ERROR crash in Parquet reader for nullable columns with filter - #102628
Conversation
…ilter Two bugs in the native Parquet V3 reader (Reader.cpp): 1. Inverted null_map check (primary fix): The memchr check at line 1422 searched for byte 0 (non-null marker) instead of byte 1 (null marker). The null_map uses standard ClickHouse convention: 1 = NULL, 0 = NOT NULL. When ALL values in a filtered subchunk were NULL and the output column was non-nullable with input_format_null_as_default=0, the check incorrectly cleared the null_map (instead of throwing CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN), leaving the column with 0 rows while rows_pass was 1, triggering: "Logical error: Unexpected number of rows in column subchunk 0 1". The inverted check also caused the opposite bug: reading non-null data from a Parquet nullable column into a non-nullable ClickHouse column with null_as_default=0 would incorrectly throw CANNOT_INSERT_NULL even when no NULLs were present. 2. Disabled filter-in-decoder for nullable columns: The use_filter_in_decoder optimization reads ALL rows through processDefLevelsForInnermostColumn (populating the null_map for all rows, not just filtered ones) and then passes the filter to the decoder. With nullable columns, the decoder applies the filter at consecutive encoded-value indices, but null rows have no encoded values, so the filter-to-row mapping is wrong. Disable this optimization for nullable columns, falling back to the correct row-range iteration path. Closes ClickHouse#99019 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Pre-PR Validation Gate (session: cron:clickhouse-ci-task-worker:20260413-221500)a) Deterministic repro? Yes: Crashes 100% of the time without the fix (Aborted/core dump). With the fix: correctly throws b) Root cause explained? Yes. The c) Fix matches root cause? Yes. Changed d) Test intent preserved / new test added? Yes. New regression test e) Demonstrated in both directions? Yes. Without fix: f) Fix is general? Yes. The memchr fix covers all nullable Parquet columns (not just the specific stress test case). The |
|
cc @al13n321 @Avogar — could you review this? It fixes an inverted |
|
Workflow [PR], commit [b5170b5] Summary: ❌
AI ReviewSummaryThis PR fixes a real correctness bug in the native Parquet V3 reader for nullable columns under filtering: the null check now correctly searches for ClickHouse Rules
Final Verdict
|
Two issues fixed: 1. Pin input_format_parquet_use_native_reader_v3=1 in all queries — the test exercises V3 reader behavior (filter pushdown); the legacy Arrow-based reader has different semantics (reads ALL rows before casting, so null_as_default=0 errors even when WHERE excludes NULL rows). 2. Add '| head -1' to grep pipeline — CI's --send_logs_level=warning causes CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN to appear in both a server log message and the exception, producing duplicate grep matches. 3. Replace section 4 (read only non-null rows from file with NULLs) with reading from a NULL-free file — the V3 reader processes data at subchunk granularity, so NULLs in the same subchunk as requested rows cause errors regardless of the WHERE filter. The new test validates the fix doesn't break the non-null case. Verified: 50/50 passes with full randomization. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Test fix pushed (commit b5170b5)The regression test Issue 1: Legacy reader path. CI randomizes Issue 2: Duplicate grep match. CI adds Issue 3: Non-deterministic section 4. The original test tried to read only non-null rows ( Verified: 50/50 passes with full randomization locally. Session: cron:clickhouse-ci-task-worker:20260415-161500 |
LLVM Coverage Report
Changed lines: 90.00% (9/10) · Uncovered code |
728336b
|
Hi @groeneai @Avogar — the changelog category for this PR might need a look. Current: Why: The PR fixes a LOGICAL_ERROR exception (which causes abort/core dump in debug builds). LOGICAL_ERROR is explicitly listed under 'Critical Bug Fix (crash, data loss, RBAC) or LOGICAL_ERROR' category, not the general 'Bug Fix' category. The linked issue #99019 confirms this reproduces on ClickHouse 26.2.4.23 (a supported stable release). Could you verify this is correct? Ignore if the current category is intentional. |
|
Hi — this PR may need backporting to Affected code: Why: The If this should be backported, consider adding |
|
Backport labels have been automatically added based on https://github.com/ClickHouse/clickhouse-core-incidents/issues/1508 Labels added:
These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels. |
|
Backport labels have been automatically added based on https://github.com/ClickHouse/clickhouse-core-incidents/issues/1509 Labels added:
These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels. |
Antalya 26.3 Backport of ClickHouse#102628 - Fix LOGICAL_ERROR crash in Parquet reader for nullable columns with filter
|
Backport labels have been automatically added based on https://github.com/ClickHouse/clickhouse-core-incidents/issues/1731 Labels added:
These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels. |
Cherry pick #102628 to 26.2: Fix LOGICAL_ERROR crash in Parquet reader for nullable columns with filter
…or nullable columns with filter
…-null-check Fix LOGICAL_ERROR crash in Parquet reader for nullable columns with filter
Backport #102628 to 26.2: Fix LOGICAL_ERROR crash in Parquet reader for nullable columns with filter
…-null-check Fix LOGICAL_ERROR crash in Parquet reader for nullable columns with filter
Antalya 26.3 Backport of ClickHouse#102628 - Fix LOGICAL_ERROR crash in Parquet reader for nullable columns with filter
|
@Avogar I might be misunderstanding how backporting process works in Clickhouse, but shouldn't this also be backported to v26.3? |
|
The backport targets come from the `vXX.Y-must-backport` labels, which were added automatically based on the linked core-incidents reports (v25.12 from #1509, v26.2 from #1731), not chosen manually. This fix was already backported to 26.2.19.43. Adding v26.3 is a release-maintainer call, so it is up to Avogar / the release team to apply the label if 26.3 should get it. As the author I do not add backport labels or open manual backport PRs myself. |
|
That's the thing: I can reproduce the issue on the most recent v26.3 LTS version. Looking at the code, it's expected – the necessary changes simply aren't there. |
|
Thanks for confirming - you are right, the fix is absent from 26.3. Only the Since 26.3 is confirmed affected, the fix should be backported there too. @Avogar could you add the For verification against 26.3 HEAD, the fix is in merge commit 728336b (two parts in the native Parquet reader: the inverted null_map memchr check, and disabling use_filter_in_decoder for nullable columns). |
|
Let's backport to 26.3 |
Backport #102628 to 26.3: Fix LOGICAL_ERROR crash in Parquet reader for nullable columns with filter
…t reader for nullable columns with filter
PROTO: Parquet V3 reader, Nullable columns with WHERE -> exc LOGICAL_ERROR. Effect in the production build a394e92: its upstream test(s) 04099_parquet_nullable_null_check_fix fail on it and pass on official 26.8.8.8, run on isolated servers (evidence/fix_ci_20260925/upstream_repro/server_triage_PROD263_vs_UP2688.tsv). Upstream patch unchanged, with its test(s): 04099_parquet_nullable_null_check_fix. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Linked issues
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix LOGICAL_ERROR crash "Unexpected number of rows in column subchunk" in native Parquet V3 reader when reading nullable columns with a WHERE filter.
What this PR fixes
Two bugs in the native Parquet V3 reader (
src/Processors/Formats/Impl/Parquet/Reader.cpp):1. Inverted null_map check (primary fix, line 1422):
The
memchrcheck searched for byte0(non-null marker) instead of byte1(null marker) in the null_map. The null_map uses standard ClickHouse convention:1 = NULL, 0 = NOT NULL, as documented in the same file:When ALL values in a filtered subchunk were NULL and the output column was non-nullable with
input_format_null_as_default=0:0found = no non-null entries)rows_passwas 1Logical error: 'Unexpected number of rows in column subchunk 0 1'The inverted check also caused the opposite problem: reading non-null data from a Parquet nullable column into a non-nullable ClickHouse column with
null_as_default=0would incorrectly throwCANNOT_INSERT_NULL_IN_ORDINARY_COLUMNeven when no NULLs were present.2. Disabled
use_filter_in_decoderfor nullable columns:The filter-in-decoder optimization processes ALL rows (passing + non-passing) through
processDefLevelsForInnermostColumn, so the null_map ends up with entries for all rows rather than just filtered rows. Additionally, the decoder applies the filter at consecutive encoded-value indices, but with nullable columns, null rows have no encoded values, so the filter-to-row index mapping is wrong. Disabled this optimization for nullable columns — the standard row-range iteration path correctly handles both issues.How it was tested
04099_parquet_nullable_null_check_fix.sh: creates a Parquet file with nullable string column (NULLs every 3rd row), verifies:null_as_default=1with non-nullable output → NULLs become empty strings ✓null_as_default=0, filter hits NULL rows →CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN(not LOGICAL_ERROR crash) ✓null_as_default=0, filter hits only non-null rows → succeeds ✓clickhouse-localCloses #99019
Version info
26.4.1.1084(included in26.4and later)26.3.17.51