Skip to content

Fix Arrow Flight returning garbage for columns stored in sparse serialization - #125553

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/arrowflight-materialize-sparse-columns
Oct 13, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/arrowflight-materialize-sparse-columns

Conversation

@groeneai

@groeneai groeneai commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #125517

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

Fixed the Arrow Flight interface returning garbage values for a MergeTree column stored in sparse serialization, which is the default for a column that holds mostly default values. Affected DoGet with a SQL ticket, GetFlightInfo and PollFlightInfo.

Description

On 26.8.21.12 and 26.3.33.24, with default MergeTree settings, DoGet of the SQL ticket SELECT x FROM t, where x is mostly zeros and its part therefore stores it sparse, returns garbage such as 139362918555712 instead of the column values. Debug and sanitizer builds abort with Logical error: 'Bad cast from type DB::IColumn const* to DB::ColumnNullable const*', which is how the stress test of #125517 found it (CI report).

Root cause: PullingPipelineExecutor returns columns as the pipeline produced them. An ordinary output format gets a MaterializingTransform from QueryPipeline::complete, but the Arrow Flight server converts the pulled blocks with CHColumnToArrowColumn directly, and the converter only undoes ColumnConst and ColumnReplicated. A ColumnSparse then fails the first assert_cast, which is a static_cast in release builds.

Change: call removeSpecialColumnRepresentations after each pull at the three places where the server reads a query result (DoGet with a SQL ticket, GetFlightInfo, PollFlightInfo), as the dictionary sources already do. Results without sparse columns are unchanged (identical Arrow IPC bytes).

Validation: the new integration test reads a sparse table through all three paths; it fails on master with the server abort and passes with the fix. Locally, all three paths return the same values as the native protocol for compact and wide parts, a DoGet of 13 sparse-capable types matches HTTP FORMAT Arrow, and all test_arrowflight_* integration tests pass.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/125553]

Version info

  • Merged into: 26.10.1.2317-master (included in 26.10 and later)

`PullingPipelineExecutor` returns columns as the pipeline produced them, so a
MergeTree column stored in sparse serialization reaches the Arrow Flight server
as a `ColumnSparse`. Ordinary output formats never see one, because
`QueryPipeline::complete` gives them a `MaterializingTransform`, but the server
converts pulled blocks with `CHColumnToArrowColumn` directly, and the converter
only undoes `ColumnConst` and `ColumnReplicated`. The first `assert_cast` to the
concrete column class then fails: a `LOGICAL_ERROR` on debug and sanitizer
builds, and garbage values on release builds, where `assert_cast` is a
`static_cast`.

Call `removeSpecialColumnRepresentations` after every `pull` at the three
places where the server reads a query result (`DoGet` with a SQL ticket,
`executeSQLtoTables_impl` behind `GetFlightInfo`, and
`PollSession::getNextBlock` behind `PollFlightInfo`), before any
`block_modifier` sees the block, as the dictionary sources and the query result
cache already do. The converter is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Oct 13, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 2 rounds; round 2 delta: 0 findings) plus my own review.

# Sev Finding Verdict Evidence / action
1 ⚠️ The test did not exercise PollFlightInfo (PollSession::getNextBlock), so removing that line kept it green AGREE, fixed @ f2c6b40 Added a PollFlightInfo arm; a build without the PollSession line fails only that arm
2 💡 The new test sat at the same anchor as another open PR's test hunk AGREE, fixed @ f2c6b40 Moved after test_doget_cmd_select_arrow_format
3 💡 materializeBlock instead of removeSpecialColumnRepresentations No change The converter already handles ColumnConst

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-8:20261013-030300

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The DDL and INSERT of 03792_sparse_offsets_in_substreams_cache_compact_part.sql, then do_get(Ticket(b"SELECT s.null, s.size from t0")), abort the master debug server every run with the CI stack (getArrowType <- calculateArrowTable <- DoGet).
b Root cause explained? Yes. PullingPipelineExecutor does not materialize sparse columns (only an IOutputFormat pipeline gets a MaterializingTransform), and the Arrow Flight server passes pulled blocks to CHColumnToArrowColumn, which handles only ColumnConst and ColumnReplicated.
c Fix matches root cause? Yes. The server, which bypasses the output format, now removes special column representations after each pull, the same operation QueryPipeline::complete and the dictionary sources apply. No try/catch, no setting.
d Test intent preserved / new tests added? Yes. New integration test test_doget_sparse_columns with one arm per server path (raw DoGet, GetFlightInfo, PollFlightInfo), and a precondition that the fixture really is sparse. No existing test changed.
e Both directions demonstrated? Yes. The test fails on master (server abort) and passes with the fix, 50/50 repeated runs. A build without the GetFlightInfo line fails the test's second arm, and a build without the PollSession line fails its third arm.
f Fix is general across code paths? Yes. All three places that pull a query result are fixed (DoGet with a SQL ticket, executeSQLtoTables_impl behind GetFlightInfo, PollSession behind PollFlightInfo); each aborts on master and returns correct data with the fix. Schema-only calls never pull; FORMAT Arrow over HTTP/TCP already materializes.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. Compact and wide parts; sparse numbers, String, Nullable (allow_sparse), subcolumns (s.size), Tuple and nested Tuple elements; 13 sparse-capable types plus LowCardinality, Array, Map controls, all equal to FORMAT Arrow over HTTP.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or protocol change; a non-sparse result gives byte-identical Arrow IPC output before and after.
i Invariants and contracts preserved? Yes. Every block converted by CHColumnToArrowColumn or passed to a block_modifier now carries no special representation; removeSpecialRepresentations keeps types, row counts and column order, and empty blocks pass through unchanged.

Session id: cron:clickhouse-impl-slot-5:20261013-025200

@clickhouse-gh

clickhouse-gh Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f2c6b40]

Summary: ✅


AI Review

Summary

This PR fixes the ArrowFlight result path by normalizing pulled blocks before they reach CHColumnToArrowColumn, so sparse on-disk representations no longer leak into converter code that only unwraps ColumnConst and ColumnReplicated. The fix is applied on all three query-result paths that actually pull data (DoGet for SQL tickets, GetFlightInfo, and PollFlightInfo), and the new integration test exercises all three against genuinely sparse columns. I did not find any correctness, concurrency, compatibility, or testing gaps in the current patch.

Final Verdict

✅ Approve — no blocking or major issues found.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-arrow-flight labels Oct 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f2c6b4099 with master efd9fd8da (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

8 translation units recompiled, 22 s compile time in total, 8 of them have a recent master baseline.

Job report

@alexey-milovidov alexey-milovidov self-assigned this Oct 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 13, 2026
Merged via the queue into ClickHouse:master with commit da2150b Oct 13, 2026
177 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 13, 2026
alexey-milovidov pushed a commit that referenced this pull request Nov 7, 2026
Resolve the conflicts in ArrowFlightServer.cpp: 26.9 does not have #115250,
#125534 and #125553, which changed the same lines (conversion settings,
the `block.empty()` check in `DoGet`, `removeSpecialColumnRepresentations`),
so their changes are left out and only #129193's lines are kept.

Leave out 05497_arrowflight_exception_on_query_finish: 26.9 has no Arrow
Flight port in the stateless test config (#125517 is master-only), so the
test cannot connect there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov pushed a commit that referenced this pull request Nov 7, 2026
Resolve the conflicts in ArrowFlightServer.cpp: 26.8 does not have #115250,
#125534 and #125553, which changed the same lines (conversion settings,
the `block.empty()` check in `DoGet`, `removeSpecialColumnRepresentations`),
so their changes are left out and only #129193's lines are kept.

Leave out 05497_arrowflight_exception_on_query_finish: 26.8 has no Arrow
Flight port in the stateless test config (#125517 is master-only), so the
test cannot connect there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-arrow-flight-protocol Apache Arrow Flight server interface: ClickHouse as a Flight server on its own port (gRPC-based d... label Nov 23, 2026
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 comp-arrow-flight-protocol Apache Arrow Flight server interface: ClickHouse as a Flight server on its own port (gRPC-based d... groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants