Skip to content

Add Arrow Flight SQL support - #91170

Merged
yakov-olkhovskiy merged 159 commits into
masterfrom
feat-arrowflight-impl
Apr 14, 2026
Merged

yakov-olkhovskiy merged 159 commits into
masterfrom
feat-arrowflight-impl

Conversation

@yakov-olkhovskiy

@yakov-olkhovskiy yakov-olkhovskiy commented Dec 1, 2025 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Add Arrow Flight SQL support

closes #89120

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Note

High Risk
High risk because it significantly refactors the Arrow Flight gRPC server, adds Flight SQL command handling and session/auth middleware, and introduces new settings that change Arrow/Parquet output behavior for unsupported types.

Overview
Adds Arrow Flight SQL support by refactoring the server implementation from ArrowFlightHandler to ArrowFlightServer, introducing commandSelector to map Flight SQL protobuf commands to SQL execution or direct arrow::Table responses, and implementing additional DoAction handlers (query cancellation and session option get/set).

Introduces a new Arrow Flight auth/session middleware (AuthMiddleware) that supports Basic auth and bearer tokens, manages ClickHouse sessions via request headers, and ties Flight descriptors to query ids for cancellation and cleanup.

Extends Arrow/Parquet output configuration with new settings (output_format_arrow_unsupported_types_as_binary, output_format_parquet_unsupported_types_as_binary) and updates the Arrow conversion layer (CHColumnToArrowColumn) to support Variant to Arrow dense union, safer index conversions, and optional fallback of unsupported types to raw binary.

Updates build and CI plumbing: enables compiling Server/ArrowFlight as a separate object library when Arrow Flight is available, adjusts CMake/protobuf helpers to support PROTOC_OUT_DIR, and expands Arrow contrib build to generate/compile Flight SQL protos and sources.

Written by Cursor Bugbot for commit 8eeb845. This will update automatically on new commits. Configure here.

Version info

  • Merged into: 26.4.1.939

@clickhouse-gh

clickhouse-gh Bot commented Dec 1, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2183149]

Summary: ❌

job_name test_name status info comment
Finish Workflow failure
python3 ./ci/jobs/scripts/workflow_hooks/feature_docs.py failure IGNORED

AI Review

Summary

This PR adds Arrow Flight SQL support, including new server handlers, auth/session middleware, command routing, and Arrow/Parquet format behavior. I found one blocker that must be fixed before merge: AuthMiddleware contains a compile-time scope error in the new auth flow. I also noted a metadata/documentation inconsistency (docs checkbox checked, but no docs/ changes in the PR).

Missing context
  • ⚠️ No CI logs/results were provided in this review environment, so this review is based on code/PR content only.
Findings
❌ Blockers
  • [src/Server/ArrowFlight/AuthMiddleware.cpp:195] credentials is declared in the if initializer (if (auto credentials = ...)) and then used in the else if branch, where it is out of scope. This is a compile-time error when USE_ARROWFLIGHT=1.
    • Suggested fix: declare credentials before the if/else if chain (or use separate per-branch locals).
💡 Nits
  • [PR metadata] The PR template marks documentation as completed (Documentation is written checked), but there are no docs/ file changes in this PR. Either add docs in this PR or uncheck/update the template statement.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ✅
No magic constants ✅
Backward compatibility ⚠️ New setting output_format_arrow_unsupported_types_as_binary defaults to true; verify intended compatibility behavior is acceptable for rollout.
SettingsChangesHistory.cpp ✅
PR metadata quality ⚠️ Docs checkbox is marked complete without corresponding docs/ changes in this PR.
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    • Fix the compile-time scope error in AuthMiddlewareFactory::StartCall (credentials out of scope in bearer-token branch).

@clickhouse-gh clickhouse-gh Bot added pr-feature Pull request with new product feature submodule changed At least one submodule changed in this PR. labels Dec 1, 2025
@vitlibar vitlibar self-assigned this Dec 8, 2025
@yakov-olkhovskiy

yakov-olkhovskiy commented Dec 10, 2025 •

Copy link
Copy Markdown
Member Author

Our current Arrow Flight SQL version is 11.0.0:
https://github.com/ClickHouse/ClickHouse/blob/master/contrib/arrow-cmake/cpp/src/arrow/util/config.h#L23
so

  • CommandStatementIngest is only available since 12.0.0 - I added support with local CommandStatementIngest protobuf definition

We do not support prepared statements:

  • ActionCreatePreparedStatementRequest
  • ActionClosePreparedStatementRequest
  • CommandPreparedStatementQuery
  • CommandPreparedStatementUpdate

@yakov-olkhovskiy
yakov-olkhovskiy marked this pull request as ready for review December 11, 2025 07:09
@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.

yakov-olkhovskiy and others added 2 commits April 14, 2026 08:51
The forwarding call used ${protobuf_generate_cpp_EXPORT_MACRO} (the prefix
from the non-grpc PROTOBUF_GENERATE_CPP function) instead of the correct
${protobuf_generate_grpc_cpp_EXPORT_MACRO}. This copy-paste error caused
any caller-provided EXPORT_MACRO to be silently ignored.

#91170

Co-authored-by: Yakov Olkhovskiy <[email protected]>
cursoragent and others added 2 commits April 14, 2026 14:24
Reorder insert-before-erase so that if multimap insert throws,
no state has been modified yet and all three synchronized structures
remain consistent.

Ref: #91170

Co-authored-by: Yakov Olkhovskiy <[email protected]>
commandSelector.cpp uses std::make_shared<DataTypeString>() but only had
a forward declaration of DataTypeString via IDataType.h. The incomplete
type caused three clang-tidy errors in the arm_tidy build.

#91170

Co-authored-by: Yakov Olkhovskiy <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.10% +0.10%
Functions 90.90% 90.90% +0.00%
Branches 76.60% 76.50% -0.10%

Changed lines: 84.45% (1684/1994) | lost baseline coverage: 6 line(s) · Uncovered code

Full report · Diff report

@yakov-olkhovskiy

Copy link
Copy Markdown
Member Author

documentation was moved to clickhouse-docs repo, will be added by this pr ClickHouse/clickhouse-docs#5760

@yakov-olkhovskiy
yakov-olkhovskiy added this pull request to the merge queue Apr 14, 2026
Merged via the queue into master with commit e02e0dd Apr 14, 2026
468 of 475 checks passed
@yakov-olkhovskiy
yakov-olkhovskiy deleted the feat-arrowflight-impl branch April 14, 2026 20:37
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 14, 2026
@yakov-olkhovskiy
yakov-olkhovskiy restored the feat-arrowflight-impl branch April 18, 2026 17:57
@yakov-olkhovskiy
yakov-olkhovskiy deleted the feat-arrowflight-impl branch April 18, 2026 18:18
pull Bot pushed a commit to Mattlk13/ClickHouse that referenced this pull request Sep 17, 2026
The `output_format_arrow_unsupported_types_as_binary` fallback wrote a column
with no first-class Arrow mapping by calling `IColumn::getDataAt` per row.
That method exposes a column's contiguous in-memory bytes, which most of the
types reaching the fallback do not have:

- `ColumnObject` (`JSON`), `ColumnVariant` (hence `ColumnDynamic`) and
  `ColumnQBit` throw `Method getDataAt is not supported`, so `SELECT ... FORMAT
  Arrow` failed on them - after the schema message had already been written,
  leaving the client with a truncated stream;
- `ColumnAggregateFunction::getDataAt` returns the `AggregateDataPtr` itself,
  so exporting an aggregate state silently wrote raw heap addresses instead of
  the state, both corrupting the data and disclosing server addresses.

Before the fallback existed these types were rejected with a clear
`UNKNOWN_TYPE`, so both are regressions introduced together with the setting.

The fallback now serializes each value through `ISerialization`, whose
`serializeText`/`serializeBinary` are pure virtual and therefore defined for
every type, so the "do not fail a `SELECT *`" property holds by construction
instead of depending on an unrelated method's implementation status. The
aggregate state written in binary mode is the `RowBinary` encoding and
deserializes back into the original `AggregateFunction` type.

`output_format_arrow_unsupported_types` (`throw`/`text`/`binary`) replaces the
boolean, adding a `text` mode that writes what `CAST(col AS String)` would
produce - useful for the BI clients that drive `SELECT *` over Arrow Flight
SQL, and the workaround users had to apply by hand for `JSON`. The default,
`binary`, is the previous behavior, so `compatibility` must not change it. The
boolean keeps working with full effect (`0` means `throw`, `1` means `binary`)
and is only consulted while the new setting is left at its default, so an
explicit mode wins whichever order the two are set in.

Both writers now decide in the schema converter, before the schema message is
written, so a rejected type can no longer abort a stream whose schema the
reader has already accepted. An opaque column is tagged with the
`clickhouse.opaque` Arrow extension name and the original ClickHouse type
name, so a consumer can tell it apart from a genuine string or binary column;
a reader that does not know the extension name sees the plain storage type.

Closes: ClickHouse#115023
Caused by: ClickHouse#91170

Co-authored-by: Yakov Olkhovskiy <[email protected]>
@alexey-milovidov alexey-milovidov mentioned this pull request Sep 20, 2026
47 of 72 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Arrow Flight SQL