Skip to content

Fix Arrow Flight DoGet of a SQL ticket with an empty result - #125534

Merged
alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
groeneai:fix-arrowflight-doget-empty-result
Oct 16, 2026
Merged

alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
groeneai:fix-arrowflight-doget-empty-result

Conversation

@groeneai

@groeneai groeneai commented Oct 12, 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 DoGet over the Arrow Flight interface failing with Check failed: (chunks_.size()) > (0) when a SQL query ticket returns no rows. It now returns an empty result with the query's schema.

Description

On 26.8.21.12 and 26.3.33.24, DoGet over Arrow Flight with the SQL ticket SELECT number FROM system.numbers LIMIT 0 fails with Code: 1001 ... chunked_array.cc:54: Check failed: (chunks_.size()) > (static_cast<size_t>(0)) cannot construct ChunkedArray from empty vector and omitted type instead of returning an empty result. Any SQL ticket whose result has no rows hits it. Found by the protocol randomization in #125517 (comment).

Root cause: for an empty result DoGet passes zero chunks to CHColumnToArrowColumn::chChunkToArrowTable, which supports that, but calculateArrowTable built each arrow::ChunkedArray without a type, and Arrow cannot infer one from an empty vector. GetFlightInfo and PollFlightInfo were not affected (they handle an empty result before this call).

Change: pass the schema field type to the ChunkedArray constructor. Every array of the column is already a view of that type, so non-empty results are unchanged (identical IPC bytes before and after); an empty one now has the schema GetFlightInfo reports for it. DoGet also skips zero-column blocks before collecting chunks, as executeSQLtoTables_impl does.

Validation: the new integration test fails on master with the error above and passes with the fix (20/20 repeats). All test_arrowflight_interface, test_arrowflight_storage and test_arrowflight_session_log tests pass, and the DeltaLake stateless tests (DeltaLake writes also go through this function) give the same results as without the fix.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.19-master (included in 26.11 and later)

`DoGet` with a raw SQL query ticket collects the pulled blocks and passes
them to `CHColumnToArrowColumn::chChunkToArrowTable`. For an empty result
there are no blocks. `chChunkToArrowTable` accepts zero chunks (it builds
the schema from the header), but `calculateArrowTable` constructed every
`arrow::ChunkedArray` without a type, and Arrow cannot derive the type
from an empty vector: `chunked_array.cc:54: Check failed:
(chunks_.size()) > (0)`, returned to the client as `Code: 1001`.

Pass the schema field type to the `ChunkedArray` constructor. It is the
type every array of the column is already viewed as, so non-empty tables
are unchanged, and an empty result now arrives as zero rows with the
query's schema, as `GetFlightInfo` already returns it.

Found by the protocol randomization in ClickHouse#125517.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 12, 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; 0 findings) plus my own cold review (2 nits).

# Sev Finding Verdict Evidence / action
1 💡 getEmptyArrowTable in ArrowFlightServer.cpp now duplicates what calculateArrowTable does for zero chunks AGREE, not changed Removing it is not mechanical: executeSQLtoTables_impl has no header for an empty result and schema_modifier may change the schema. Kept out of this minimal fix.
2 💡 The raw-SQL DoGet loop does not skip a zero-column block as the sibling loops do AGREE, not changed PullingPipelineExecutor::pull returns a cleared block only on a CPU-lease downscale, which the pulling (master) slot never takes; unrelated to the empty-result case.

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

Session id: cron:clickhouse-review-slot-8:20261012-233400

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. client.do_get(flight.Ticket(b"SELECT number FROM system.numbers LIMIT 0")) fails every time on master, 26.8.21.12 and 26.3.33.24 with chunked_array.cc:54: Check failed: (chunks_.size()) > (0).
b Root cause explained? Yes. An empty result gives DoGet zero chunks; calculateArrowTable built each arrow::ChunkedArray without a type, and Arrow cannot infer one from an empty vector, so its ARROW_CHECK throws and DoGet returns the error.
c Fix matches root cause? Yes. The untyped constructor in the shared converter now gets the schema field type; no caller-side special case.
d Test intent preserved / new tests added? Yes. New integration test test_doget_ticket_from_select_empty_result checks the schema and zero rows; no existing test changed.
e Both directions demonstrated? Yes. The new test fails on the unfixed build with the error above and passes with the fix (20/20 repeats).
f Fix is general across code paths? Yes. All callers checked: raw-SQL DoGet (the bug), GetFlightInfo/prepared statements (already return an empty typed table), PollFlightInfo (no call with zero chunks), StorageArrowFlight and DeltaLake writes (always one chunk). Their test suites pass.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. Empty results checked for Nullable, LowCardinality, LowCardinality(Nullable), Array, Tuple, Map, UUID, Decimal, DateTime64, a constant-only query and several columns.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or format change; non-empty results produce identical Arrow IPC bytes before and after.
i Invariants and contracts preserved? Yes. Each column's declared type is the schema field type, which every chunk already had (View/Equals), so the table is unchanged for one or more chunks and now valid for zero.

Session id: cron:clickhouse-impl-slot-4:20261012-225700

@clickhouse-gh

clickhouse-gh Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [99c484f]

Summary: ✅


AI Review

Summary

Reviewed #125534 at 99c484fb9ccb2646cb24e2286a92c7d7eb11eed2. The change fixes empty Arrow Flight DoGet results by supplying schema field types to arrow::ChunkedArray and filtering zero-column pipeline blocks. The regression test checks the returned schema and zero rows, with passing CI evidence. The prior inline finding is addressed; no unresolved findings remain.

Final Verdict

✅ Approve.

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

clickhouse-gh Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 99c484fb9ccb2646cb24e2286a92c7d7eb11eed2 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

@alexey-milovidov alexey-milovidov self-assigned this Oct 13, 2026
`PullingPipelineExecutor::pull(Block &)` can return true with a cleared
block, and `calculateArrowTable` indexes `getColumns()` of every chunk it
receives. Skip such blocks before collecting chunks, as
`executeSQLtoTables_impl` already does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, fix conflicts.

Also, about 05210_lightweight_update_materialized_cte_in_ignore - what is the problem?

@groeneai

Copy link
Copy Markdown
Collaborator Author

Conflicts fixed by merging master (16b165e). Only the DoGet loop conflicted, with #125553; it now has both the !block.empty() skip and removeSpecialColumnRepresentations. All 204 Arrow Flight integration tests pass on the merged build.

05210_lightweight_update_materialized_cte_in_ignore is unrelated to this PR. It is the race from #112642: with parallel replicas and a local plan, the initiator gates only its local read on the MATERIALIZED CTE's writer, so the remote read starts before the CTE is built, sendExternalTables skips it, and the replica fails with UNKNOWN_TABLE on _materialized_cte_c_* (all 128 reruns in that job passed). It fails on 40-50 PRs a day and on master. My fix is #123121 (open, waiting for review).

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 16b165e

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Performance Comparison (arm_release, master_head, 1/6) / (no test row) infra, not from this PR: performance dashboard verdict unavailable, the shard's results were not uploaded to CIDB (LogCluster connection failed: ConnectionError) during the 2026-10-14 ~09:00-09:50Z CIDB outage; own report: 5 too long, 1 slower #125734 (mine, open)
Performance Comparison (arm_release, master_head, 2/6) / (no test row) infra, not from this PR: performance dashboard verdict unavailable, the shard's results were not uploaded to CIDB (LogCluster connection failed: ConnectionError) during the 2026-10-14 ~09:00-09:50Z CIDB outage; own report: 5 too long, 2 unstable #125734 (mine, open)
Performance Comparison (arm_release, master_head, 3/6) / (no test row) infra, not from this PR: performance dashboard verdict unavailable, the shard's results were not uploaded to CIDB (LogCluster connection failed: ConnectionError) during the 2026-10-14 ~09:00-09:50Z CIDB outage; own report: 3 too long #125734 (mine, open)
Performance Comparison (arm_release, master_head, 4/6) / (no test row) infra, not from this PR: performance dashboard verdict unavailable, the shard's results were not uploaded to CIDB (LogCluster connection failed: ConnectionError) during the 2026-10-14 ~09:00-09:50Z CIDB outage; own report: 4 too long, 1 unstable #125734 (mine, open)
Performance Comparison (arm_release, master_head, 5/6) / (no test row) infra, not from this PR: performance dashboard verdict unavailable, the shard's results were not uploaded to CIDB (LogCluster connection failed: ConnectionError) during the 2026-10-14 ~09:00-09:50Z CIDB outage; own report: 10 too long #125734 (mine, open)
Performance Comparison (arm_release, master_head, 6/6) / (no test row) infra, not from this PR: performance dashboard verdict unavailable, the shard's results were not uploaded to CIDB (LogCluster connection failed: ConnectionError) during the 2026-10-14 ~09:00-09:50Z CIDB outage; own report: 6 too long, 1 unstable #125734 (mine, open)
Mergeable Check, PR praktika rollups of the rows above #125734 (mine, open)

These six rows are a re-run (07:49-09:24Z). The first run of the same six shards on this head passed (02:18-03:50Z), with the same and_function #0 query reported slower in 1/6. CIDB has no other FAIL or ERROR row on this head; the Bugfix validation (integration tests, *) rows of test_arrowflight_interface are the inverted ones (both jobs green).

Session id: cron:our-pr-ci-monitor:20261014-123006

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Both CI failures on 2b3c0d18 are unrelated to this PR, and each already has a fix in progress:

I merged master to refresh the branch. The merge was clean.

alexey-milovidov pushed a commit that referenced this pull request Nov 7, 2026
Resolve the conflict in ArrowFlightServer.cpp: 26.10 does not have #125534
(the `block.empty()` check in `DoGet`), so that check is left out and only
#129193's lines are kept.

Leave out 05497_arrowflight_exception_on_query_finish: 26.10 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.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-request PR origin: a maintainer pinged or directed groeneai 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