Skip to content

Read big-endian Arrow IPC files and streams - #126562

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
JayPokale:arrow-big-endian
Oct 20, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
JayPokale:arrow-big-endian

Conversation

@JayPokale

@JayPokale JayPokale commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #125138
Related: #125134

The native Arrow IPC reader rejected every big-endian file and stream (Big-endian Arrow IPC streams are not supported by the native reader). Arrow records the endianness in the schema, and readers may byte-swap the buffers, as Arrow C++ does. This PR does that:

  • prepareBuffers copies the uncompressed body of a big-endian batch once, since the body belongs to the caller (a compressed body is already decompressed into decompressed_body). It copies the whole body rather than each buffer, so overlapping buffers in a malformed file cannot multiply the allocation.
  • convertBuffersFromBigEndian walks the batch layout with advanceField, which already knows each buffer's element width, and byte-swaps every buffer it passes, then rewinds the cursors. It runs for record batches and for dictionary batches.
  • Validity bitmaps, booleans, binary data and fixed-size binary values are bytes and stay as they are. Integers, floats, dates, times, timestamps, durations, offsets, dictionary indices and union offsets are reversed element by element; decimals are reversed whole. Day-time intervals are two 32-bit integers, month-day-nano intervals are swapped per component, and binary views swap the length and, for out-of-line values, the buffer index and offset.

The test reads the big-endian integration files of apache/arrow-testing (data/arrow-ipc-stream/integration/1.0.0-bigendian, commit 9ff285c8): 17 streams and one file in the Arrow format, covering primitives with 32- and 64-bit offsets, dates and times, decimals of 128 and 256 bits, dictionaries (also nested and unsigned), lists, maps, structs and extension types. The two decimal streams are cut to their schema and first record batch, keeping the messages byte for byte, to keep the files small. The reference is the output of the current master build for the little-endian versions of the same files: the schema, the first rows, and a hash of every row.

The corpus files whose little-endian versions cannot be read yet (interval, union, null, duplicate_fieldnames) are left out. When #125134 is merged, the big-endian lines of its 05361_arrow_testing_corpus.reference will need the new output.

List-view buffers are not swapped here because master only skips list views; #126014 adds their decoding, and whichever of the two is merged second will add the swap for their offsets and sizes.

Changelog category (leave one):

  • Improvement

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

The native Arrow IPC reader can read big-endian Arrow files and streams.


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

Version info

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

The native reader rejected every big-endian file. Byte-swap the buffers of a big-endian batch to little-endian
before decoding, as Arrow C++ does: walk the batch layout with `advanceField`, which knows each buffer's element
width, and reverse each element in place. Day-time and month-day-nano intervals are swapped per component, binary
views per integer field, fixed-size binary not at all. The uncompressed body is copied once first, since it
belongs to the caller.

Closes: ClickHouse#125138
@clickhouse-gh clickhouse-gh Bot added the comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). label Oct 18, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good.

@alexey-milovidov alexey-milovidov self-assigned this Oct 19, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [efbc256]

Summary: ✅


AI Review

Summary

The PR enables big-endian Arrow IPC input by converting record-batch and dictionary buffers before decoding, with corpus tests covering schemas, sample values, and hashes of all rows. No actionable correctness or safety findings were identified.

Missing context / blind spots
  • ⚠️ Runtime validation remains pending: 05407_arrow_big_endian is excluded from Fast test, and targeted stateless CI was still pending when inspected. No local ClickHouse binary was available. A successful stateless run of the new test would close this gap.
Final Verdict

✅ Approve on code review; the new regression test still needs its normal stateless CI run.

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements external Author is not a member of the ClickHouse organization labels Oct 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing efbc256a4 with master c8d67a8a9 (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

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

Job report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 20, 2026
Merged via the queue into ClickHouse:master with commit cb492be Oct 20, 2026
178 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 20, 2026
cursor Bot pushed a commit that referenced this pull request Nov 19, 2026
Resolve the conflicts of the cherry-pick of #132416 to 26.9. The fix applies in full; the differences
from the original diff come only from master-only neighbours that 26.9 does not have:

- `ArrowIPCBlockInputFormat.cpp`: 26.9 still checks that dictionary values are unique after registering
  them (master dropped the check in #125677). Keep the check and look the values up by the dictionary use,
  as the registry is now keyed by it.
- `RecordBatchDecoder.cpp`: 26.9 has no `TypeKind::RunEndEncoded` case in `collectDictionaryUses`
  (run-end encoding, #126207, is master-only), so there is no call to pass `below_union` to there.
  The struct case keeps the 26.9 helpers `tupleElementHint` / `childPath` (master renamed them in
  #125674) and passes `below_union` as the original change does.
- `RecordBatchDecoder.cpp`: include `base/scope_guard.h` for the two new `SCOPE_EXIT` uses. On master
  the include came with the big-endian reader (#126562); 26.9 does not include it, directly or
  transitively.
- `RecordBatchDecoder.h`: no `[[nodiscard]]` on the changed declarations, as on the rest of the 26.9
  file (master added them in #126158).

Co-authored-by: yakov <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 19, 2026
Resolve the conflicts of the cherry-pick of #132416 to 26.10. The fix applies in full; the differences
from the original diff come only from master-only neighbours that 26.10 does not have:

- `RecordBatchDecoder.cpp`: 26.10 has no `TypeKind::RunEndEncoded` case in `collectDictionaryUses`
  (run-end encoding, #126207, is master-only), so there is no call to pass `below_union` to there.
  The struct case keeps the 26.10 helpers `tupleElementHint` / `childPath` (master renamed them in
  #125674) and passes `below_union` as the original change does.
- `RecordBatchDecoder.cpp`: include `base/scope_guard.h` for the two new `SCOPE_EXIT` uses. On master
  the include came with the big-endian reader (#126562); 26.10 does not include it, directly or
  transitively.
- `RecordBatchDecoder.h`: no `[[nodiscard]]` on the changed declarations, as on the rest of the 26.10
  file (master added them in #126158).

Co-authored-by: yakov <[email protected]>
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-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). external Author is not a member of the ClickHouse organization pr-improvement Pull request with some product improvements 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.

Arrow: big-endian Arrow IPC files and streams are not supported

3 participants