Skip to content

Cherry pick #102628 to 26.2: Fix LOGICAL_ERROR crash in Parquet reader for nullable columns with filter - #105310

Merged
robot-ch-test-poll2 merged 4 commits into
backport/26.2/102628from
cherrypick/26.2/102628
May 19, 2026
Merged

robot-ch-test-poll2 merged 4 commits into
backport/26.2/102628from
cherrypick/26.2/102628

Conversation

@robot-ch-test-poll2

Copy link
Copy Markdown
Contributor

Original pull-request #102628

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 4 commits April 13, 2026 23:00
…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 #99019

Co-Authored-By: Claude Opus 4.6 <[email protected]>
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]>
Fix LOGICAL_ERROR crash in Parquet reader for nullable columns with filter
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels May 19, 2026
@robot-ch-test-poll2
robot-ch-test-poll2 merged commit bfe5f37 into backport/26.2/102628 May 19, 2026
@robot-ch-test-poll2
robot-ch-test-poll2 deleted the cherrypick/26.2/102628 branch May 19, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants