Skip to content

Read and write Vortex without the Apache Arrow C++ library - #131773

Merged
alexey-milovidov merged 12 commits into
masterfrom
vortex-without-arrow
Nov 23, 2026
Merged

alexey-milovidov merged 12 commits into
masterfrom
vortex-without-arrow

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Part of removing the Apache Arrow C++ library: the Vortex format no longer uses it.

The Vortex library exchanges data with ClickHouse through the Arrow C data interface. Chunks were imported with arrow::ImportRecordBatch and ArrowColumnToCHColumn, and written with CHColumnToArrowColumn and Arrow's C bridge. Now both directions go through the native Arrow IPC code of the Arrow format.

Import:

  • ArrowIPC::importSchemaFromC turns a C schema into the IPC Schema FlatBuffer and parses it with the native parseSchema, so all of its validation applies.
  • ArrowIPC::importRecordBatchFromC decodes a C array with RecordBatchDecoder without copying its buffers, via a new RecordBatchDecoder::decodeExternalBatch that takes the pre-ordered field nodes and buffer slices directly. The C data interface lets an array (and, for structs, fixed-size lists and sparse unions, its children) start at an offset: buffers are sliced accordingly, and bitmaps not starting at a byte boundary are re-packed.
  • ArrowIPC::buildChunk (the conversion of decoded columns to the header, from the Arrow input format) is shared with Vortex.

Export uses the exporter of #131768 (this PR includes it). It gains three writer choices that Vortex needs and the Arrow format does not use: FixedString as Binary, DateTime as a timestamp in seconds, and Nothing as Null. Buffers that are not aligned to 16 bytes are copied, because arrow-rs checks the alignment of 128-bit values.

The filter pushdown and the scan planner use the Arrow-free schema description. The file is read through a small Vortex::VortexFile instead of an Arrow RandomAccessFile. Schema inference keeps the old behavior. USE_VORTEX no longer needs the Arrow library.

Tested locally:

  • the Vortex stateless tests and all stateless tests mentioning Arrow/ArrowStream (246 tests) pass, except those that also fail with a master build in my environment (S3, schema registry, missing test.hits, etc.);
  • the Arrow IPC part was checked against a master build on the same tests.

Related: #131768

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.12.1.221-master (included in 26.12 and later)

alexey-milovidov and others added 2 commits November 15, 2026 09:37
The Vortex library exchanges data with ClickHouse through the Arrow C data
interface. Chunks were imported with `arrow::ImportRecordBatch` and converted with
`ArrowColumnToCHColumn`, and written with `CHColumnToArrowColumn` and Arrow's C
bridge. Now they go through the native Arrow IPC code:

- `ArrowIPC::importSchemaFromC` turns a C schema into the IPC `Schema` the native
  reader parses, and `importRecordBatchFromC` decodes a C array with
  `RecordBatchDecoder` without copying its buffers: a new
  `RecordBatchDecoder::decodeExternalBatch` takes the field nodes and the buffers
  directly. Arrays with an offset are sliced, and their bitmaps re-packed.
- `ArrowIPC::buildChunk` (the conversion of the native `Arrow` format to the
  header) and `ArrowIPC::inferColumns` (its schema inference) are shared with
  Vortex.
- Writing uses the exporter of the Delta Lake writes, with three new choices of
  the native writer that Vortex needs (`FixedString` as `Binary`, `DateTime` as a
  timestamp, `Nothing` as `Null`).
- The filter pushdown and the scan planner use the Arrow-free schema description,
  and the file is read through a small `Vortex::VortexFile` instead of an Arrow
  `RandomAccessFile`.

`USE_VORTEX` no longer needs the Arrow library.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lease only what the library does not take

- arrow-rs requires the buffers it imports to be aligned to their values (16 bytes
  for 128-bit integers), while the IPC body aligns them to 8 bytes: the exporter
  copies a buffer that is not aligned to 16 bytes.
- The C array exporter never compresses the buffers.
- `vortex_ffi_writer_create` and `vortex_ffi_writer_write` move the schema and the
  array out without marking ours released, so they are released only when an
  exception comes before the call.
- The types of Vortex files are inferred as the Arrow library reader inferred them
  under `schema_inference_make_columns_nullable = 1`: the elements of a nullable
  struct keep their nullability.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [63de5bb]

Summary: ✅


AI Review

Summary

The PR routes Vortex schema and column conversion through the native Arrow implementation, removing its dependency on the Apache Arrow C++ library. Reviewed head 63de5bbc52300c41c5a51758775443dcbc86510b and all prior discussion. All four previous findings are addressed; the remaining bot thread has been resolved. No new actionable findings.

The decoded-column consumers are covered: onChunk materializes constants before ArrowIPC::buildChunk, the row-index path materializes its column before accessing its values, and readWithoutColumns supplies an empty decoded-column collection. The existing Arrow reader retains its normalization before the shared conversion.

Missing context / blind spots
  • ⚠️ No compiled ClickHouse binary was available for local execution. Runtime evidence relies on the author's reported local runs and the regression tests in the PR. The latest Praktika reports do not yet contain Vortex functional-test results; completed Vortex-enabled CI would close this validation gap.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Nov 15, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). label Nov 15, 2026
alexey-milovidov and others added 4 commits November 18, 2026 17:49
Resolved conflicts: kept both the `Nothing` as `Null` and the `Variant` as JSON text branches in `RecordBatchEncoder::encodeField`; kept the Arrow-free types with master's `[[nodiscard]]` in `VortexExpressionConverter.h`.
… Vortex schema inference

`RecordBatchDecoder` returns constants for `Null` fields and bufferless structs, while `ArrowIPC::buildChunk`
expects full columns, as the `Arrow` input format provides them. Reading such a field as another type,
e.g. `Nullable(UInt64)`, hit an `assert_cast` on the constant column. Materialize the decoded columns of
each piece before building the chunk.

With `schema_inference_make_columns_nullable = 0`, remove `Nullable` at every depth of the inferred
types (except around `Nothing`), as the Apache Arrow library reader did, via the same helper that the
`Arrow` format schema reader uses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`ArrayBuilder::nextBuffer` copies a buffer that is not aligned to 16 bytes into a `PODArray`, but a small
allocation is aligned only to its size: an 8-byte buffer (e.g. the offsets of a one-row batch) got an
8-aligned copy, and the `chassert` failed in debug builds on `05339_vortex_iceberg_mixed_write_format`
and on Delta Lake writes. Request the 16-byte alignment from the allocator.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=131773&sha=789ecd0e04f23b379c14e1c41c14f4ec29525d48&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29
PR: #131773

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

Copy link
Copy Markdown
Member Author

🕵 Merged master (conflicts in RecordBatchEncoder.cpp and VortexExpressionConverter.h) and the latest #131768 (which fixes the UBSan "call through pointer to incorrect function type" in WriteTransaction::commit that failed every Delta Lake write in the sanitizer builds). Fixed the chassert on the 16-byte alignment of copied buffers in ArrayBuilder::nextBuffer (05339_vortex_iceberg_mixed_write_format in the debug build), and addressed both review threads with a new test.

@groeneai, investigate the failure of the Build profile diff job: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=131773&sha=789ecd0e04f23b379c14e1c41c14f4ec29525d48&name_0=PR&name_1=Build%20profile%20diff (LogClusterNotReady: the endpoint never became ready, an infrastructure issue unrelated to this PR) and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

The fix is #129675 (mine, open). In this run (job log) all 8 readiness probes to the CI logs cluster ended Read timed out. (read timeout=3), after which has_pr_data raised LogClusterNotReady. With #129675 a timed-out probe raises LogClusterUnavailable instead, which main already reports as a CI logs cluster outage (green, nothing compared) rather than failing the check.

alexey-milovidov and others added 4 commits November 21, 2026 12:59
…schema

`master` added `VortexExpressionConverter::convertEmpty`, which took the type of
the column from an `arrow::Field`. After merging it into this branch the type
comes from `ArrowIPC::ArrowField`, like in the other conversions.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
`vortex_ffi_scan_create` returned a live scan, but the member `scan` was assigned
only after `ArrowIPC::importSchemaFromC`, which allocates and can throw. In that
case `closeReader` found no scan to cancel and free, and the handle leaked. Now the
member is assigned right after the scan is created.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (no textual conflicts, but one semantic one: the new convertEmpty of the filter pushdown still took the column type from an arrow::Field; adapted in eafb806). Fixed the arm_tidy build (modernize-use-nodiscard on the getters of VortexFile) and addressed the review thread about the ownership of the started scan.

Checked locally: the build, clang-tidy on the Vortex sources and ArrowCData.cpp (clean), and 36 of the 38 Vortex stateless tests pass; the other two (05331_vortex_lazy_materialization_object_storage, 05507_lazy_materialization_object_storage_parallel_readers_vortex) need S3, which was not available in my environment.

Thanks for the pointer to #129675 for the Build profile diff failure.

@clickhouse-gh

clickhouse-gh Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 63de5bbc5 with master 69e911d89 (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.

Object file sizes

491 object files changed (+237.57 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/ArrowIPC/ArrowCData.cpp.o 165.25 KiB 282.07 KiB +116.82 KiB (+70.70%)
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Vortex/VortexBlockInputFormat.cpp.o 327.28 KiB 382.00 KiB +54.72 KiB (+16.72%)
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Vortex/VortexFFIHelpers.cpp.o 67.80 KiB 96.35 KiB +28.55 KiB (+42.10%)
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Vortex/VortexBlockOutputFormat.cpp.o 187.23 KiB 162.21 KiB -25.02 KiB (-13.36%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

@stresshouse

stresshouse Bot commented Nov 21, 2026

Copy link
Copy Markdown

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 29 queries analysed

This PR found no performance changes caused by the PR. It only changes the Arrow format and Vortex file-reading code, plus the build setting that switches Vortex on and new tests; none of the ClickBench or TPC-H queries read or write those formats. The only flagged query, ClickBench Q31 (a GROUP BY on WatchID and ClientIP, 215 ms to 251 ms, +16.7%), stays inside master's recent range of 202–258 ms and is often unstable on master. The automated decision to leave it as inconclusive matches the code changes.

clickbench

⚠️ 1 inconclusive

Flagged queries (1 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 31 not_sure 215 251 +16.7% <0.0001 aggregation: Q31 is a MergeTree GROUP BY on WatchID and ClientIP with FORMAT Null, so it never runs the Arrow or Vortex code this PR changes. The +16.7% falls inside master's own range, and this query is noisy on master.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 49a80dd9-7ce9-40ba-a5ae-5fd8d133e373
  • MIRAI run: f17a461d-6c11-4fd1-b86f-54c67069e40f
  • PR check IDs:
    • clickbench_667637_1795274232
    • clickbench_667644_1795274232
    • tpch_adapted_1_official_667680_1795274232
    • tpch_adapted_1_official_667701_1795274233

alexey-milovidov and others added 2 commits November 22, 2026 20:12
…w` settings

`getArrowFormatSettings` of the Vortex writer now starts from the default `output_format_arrow_*` settings, so
`output_format_arrow_date_as_uint16` (enabled by older `compatibility` values) no longer turns a `Date` into a number.
Test `05839_vortex_date_ignores_arrow_settings` checks both cases; its reference is the output of the build before
this PR.

Also copy under-aligned buffers of the exported `ArrowArray` into a `Memory` with 16-byte alignment: `PODArray`
does not guarantee the alignment of its data, which failed the assertion in debug builds
(`05830_vortex_null_columns_and_non_nullable_inference`).

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

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good.

@alexey-milovidov alexey-milovidov self-assigned this Nov 23, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 23, 2026
Merged via the queue into master with commit 36dc19f Nov 23, 2026
196 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). pr-not-for-changelog This PR should not be mentioned in the changelog 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