Repository navigation
Native reader and writer for the Arrow and ArrowStream formats - #106522
Conversation
First step towards a native ClickHouse reader and writer for the `Arrow` and `ArrowStream` formats that does not use the Apache Arrow C++ library. This commit adds only the scaffolding: - New directory `src/Processors/Formats/Impl/ArrowIPC` with stub classes `ArrowIPCBlockInputFormat`, `ArrowIPCBlockOutputFormat`, `ArrowIPCSchemaReader` (currently throwing `NOT_IMPLEMENTED`) and `FlatBuffersCommon.h`, which is the single place that includes the FlatBuffers-generated Arrow IPC metadata headers. - A CMake interface target `ch_contrib::arrow_ipc_metadata` exposing those generated headers plus the FlatBuffers library, linking `_flatbuffers` and never the Arrow runtime. `_flatbuffers` headers are now `SYSTEM` so they do not trip `-Werror`. - New settings `input_format_arrow_use_native_reader` and `output_format_arrow_use_native_writer` (default `false` for now). The format registration dispatches to the native or the library implementation based on them; the schema-cache key includes the reader choice. The native code is gated by `USE_ARROW` and decodes/encodes IPC buffers directly to/from ClickHouse columns; only the FlatBuffers metadata layer is shared with Arrow. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Implements the native ClickHouse reader for the `ArrowStream` format for flat (non-nested), uncompressed types, selected with `input_format_arrow_use_native_reader`. No Apache Arrow C++ library is used: the IPC metadata is parsed with the FlatBuffers-generated headers and record-batch buffers are decoded directly into ClickHouse columns. New modules under `src/Processors/Formats/Impl/ArrowIPC`: - `MessageReader` — encapsulated-message framing (continuation token, little-endian metadata length, FlatBuffer `Message`, body) with the same anti-DoS guard on the first bytes as the library-based reader. - `SchemaConverter` — parses the IPC `Schema` FlatBuffer into an Arrow-free type tree and maps fields to ClickHouse types (integers, floats, `Bool`, decimals, `Date32`, `DateTime`, `DateTime64`/time, `String`/`FixedString`). - `RecordBatchDecoder` — walks the pre-ordered flattened `nodes`/`buffers`, slicing the single message body with bounds checks on every access. Handles the LSB-first validity bitmap (inverted relative to the ClickHouse null map), `i32`/`i64` string offsets with the trailing-terminator difference, and decimals stored wider in Arrow than in ClickHouse (low-bytes-per-row copy). - `ArrowIPCBlockInputFormat` / `ArrowIPCSchemaReader` — wire the decoder into `IInputFormat`/`ISchemaReader`: name matching, `castColumn` to the output header, missing-column handling, `need_only_count` (metadata-only), the `eof` keepalive, and `schema_inference_make_columns_nullable` parity (0/1/auto) with the library reader. The native reader produces output identical to the Arrow-library reader on flat types, verified by the new test `04314_native_arrow_ipc_reader_flat`. The file format, nested types, dictionaries and body compression are added in later steps. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Extends the native `ArrowStream` reader to nested and dictionary-encoded types: - `Array`/`LargeList`/`FixedSizeList` -> `Array`, `Struct` -> `Tuple`, `Map` -> `Map`, decoded recursively from the flattened nodes/buffers with offset bounds checks and a child-size consistency check. - Dictionary-encoded fields -> `LowCardinality`. A new `DictionaryRegistry` stores the values decoded from `DictionaryBatch` messages (replacement and delta); the record-batch decoder gathers the indices via `IColumn::index`, combining index-validity nulls with null entries inside the dictionary (so both the pyarrow and ClickHouse-writer null conventions round-trip). The schema reader infers `LowCardinality(value type)` for dictionary columns, matching the Apache Arrow library reader. Verified identical to the library reader (schema and data) on Array/Tuple/Map/nested-Array and LowCardinality including LowCardinality(Nullable) by the new test `04315_native_arrow_ipc_reader_nested`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Adds support for the `Arrow` (file) format to the native reader. The file format keeps a footer (schema plus the locations of all dictionary and record batches as `Block`s) at the end of the file and is read with random access: - `readArrowFileFooter` (shared by the input format and the schema reader) verifies the leading and trailing `ARROW1` magic, reads the footer FlatBuffer, and returns the schema plus the dictionary and record-batch block offsets. The input size is obtained via `getFileSizeFromReadBuffer` rather than `SEEK_END`, which mmap-backed buffers reject. - The input format seeks to each block to read record batches on demand (so `need_only_count` reads just the batch metadata); all dictionary batches are decoded up front. When the input is not seekable it is loaded into memory and wrapped in a `ReadBufferFromMemory`, matching the Apache Arrow library's behaviour. Verified identical to the library reader (schema, data, and count) on a multi-record-batch file containing a dictionary column, via the new test `04316_native_arrow_ipc_reader_file`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Implements the native ClickHouse writer for the `Arrow` and `ArrowStream` formats, selected with `output_format_arrow_use_native_writer`. No Apache Arrow C++ library is used: ClickHouse columns are encoded directly into Arrow IPC record-batch buffers and the FlatBuffers metadata is built natively. New modules under `src/Processors/Formats/Impl/ArrowIPC`: - `MessageWriter` — encapsulated-message framing with the metadata zero-padded so each body starts 8-byte aligned, the end-of-stream marker, and raw writes (file magic). Returns each message's location so the file writer can record footer `Block`s. - `RecordBatchEncoder` — walks ClickHouse columns into the flattened FieldNode/Buffer lists and a single 8-byte-aligned body: bit-packed validity (1 = valid) and bit-packed `Bool`, `i32` string offsets (this `ColumnString` stores no trailing `\0`), decimals sign-extended to Arrow's 16/32-byte width, `DateTime64` rescaled to the nearest Arrow time unit, `Date` widened to `date32`, and recursion for Array/Tuple/Map. `Const` is materialized; `LowCardinality` is written as its full column (matching `output_format_arrow_low_cardinality_as_dictionary=false`). - `SchemaConverter::buildSchemaMessage` / `buildFooter` build the IPC `Schema` message and the file `Footer` FlatBuffers, mirroring the encoder's type choices. - `ArrowIPCBlockOutputFormat` — writes the schema, one record-batch message per chunk, then the end-of-stream marker (stream) or the footer + length + trailing magic (file). Native-written data reads back identically to data written by the Apache Arrow library writer, for both formats and a wide type matrix, verified by the new test `04317_native_arrow_ipc_writer`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Adds per-buffer body compression to the native reader and writer. Arrow IPC compresses each body
buffer independently as an 8-byte little-endian uncompressed length followed by the compressed
bytes (or, when the length is -1, the bytes stored uncompressed); the `RecordBatch` carries a
`BodyCompression{codec, BUFFER}` and the schema advertises the `COMPRESSED_BODY` feature.
- `BufferCompression` wraps the LZ4 frame (`lz4frame.h`) and ZSTD (`zstd.h`) codecs, whose frame
formats match Arrow's `LZ4_FRAME` and `ZSTD`.
- The reader decompresses all buffers of a compressed batch up front into a private body and then
decodes as usual; the writer compresses each buffer, falling back to storing it uncompressed
(prefix -1) when compression does not shrink it, driven by `output_format_arrow_compression_method`.
Verified that LZ4_FRAME and ZSTD round-trip through every writer/reader combination, including
native-write -> library-read and library-write -> native-read, by the new test
`04318_native_arrow_ipc_compression`.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Extends the native reader/writer to more ClickHouse types: - UUID round-trips as the self-describing Arrow extension type: written as fixed_size_binary(16) with the two 64-bit halves byte-reversed and an `ARROW:extension:name = arrow.uuid` field metadata; the reader recognises that metadata and reverses the swap. Cross-compatible with the Apache Arrow library (type and value preserved). - The writer now supports IPv4 (uint32), IPv6 and big integers (fixed_size_binary 16/32) and Interval (Arrow duration for sub-second kinds, int64 otherwise), so those columns no longer throw. - The reader handles half-float (-> Float32) and Arrow duration (-> Interval). On schema inference IPv4/IPv6/big integers map to UInt32/FixedString exactly as the Apache Arrow library reader does. Verified by the new test `04319_native_arrow_ipc_extra_types`. Variant<->Union, BinaryView/Utf8View reading, GeoParquet metadata and JSON-as-string remain on the library path for now; the native formats stay opt-in via the settings. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Records `input_format_arrow_use_native_reader` and `output_format_arrow_use_native_writer` in the settings changes history for the current release. The settings remain opt-in (default false) for now: the native reader/writer cover the common type set and are fully cross-compatible with the Apache Arrow library, but a few types (Variant/Union, BinaryView/Utf8View reading, GeoParquet metadata, JSON-as-string) still require the library path, so making native the default safely needs either that remaining coverage or a transparent library fallback. Until then the formats are selected explicitly via the settings. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…rectness fixes (P8) Substantially extends the native reader/writer's coverage and correctness, found by running it against the full existing Arrow test suite. The settings stay opt-in (default false). Reader: - BinaryView/Utf8View read into String (handles `variadicBufferCounts` and inline vs out-of-line views). - Type-hint conversions when the requested column type differs from the natural Arrow type: big integers and UUID reinterpreted from fixed_size_binary (castColumn cannot), and `input_format_null_as_default` honoured when a nullable Arrow column is read into a non-nullable ClickHouse column (looking through LowCardinality, which can hold nulls without being Nullable itself). - Do not wrap Array/Map/Tuple in Nullable (illegal in ClickHouse) — drop the outer validity, matching the library reader; empty Tuple() and zero-length / placeholder-offset (-1) buffers are handled. - The Arrow file format over a non-seekable input (e.g. INSERT from a pipe) is loaded into memory; the size is taken from `tryGetFileSizeFromReadBuffer` rather than a `SEEK_END` that pipes reject. - Duplicate column names are rejected with DUPLICATE_COLUMN. Writer: - Honour `output_format_arrow_date_as_uint16`. - Fall back to the Apache Arrow library writer (via the format registration) for types the native encoder does not support (e.g. Variant) and for dictionary-encoded LowCardinality output (`output_format_arrow_low_cardinality_as_dictionary`). With the settings enabled, the native reader/writer now produce results identical to the Apache Arrow library across the common type matrix; the new 04314-04319 tests cover this. Making native the default still needs Variant<->Union, GeoParquet metadata, nested null_as_default and a few dictionary edge cases, so the formats remain selectable via the settings for now. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…_size_binary (P9) When reading a fixed_size_binary(16) column into a UUID column via a type hint (e.g. a pyarrow file that stores a UUID as plain binary(16) without the arrow.uuid extension), the value must be reinterpreted with the same 64-bit-half reversal the Apache Arrow library import uses. The reinterpret branch was being shadowed by the input_format_null_as_default branch (the field is nullable), so it fell through to a plain castColumn that produced byte-swapped garbage. Reorder so the UUID and big-integer reinterpret branches run before the null_as_default handling. Verified by 04042_arrow_uuid_import and 04039_arrow_uuid passing under the native reader. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Makes `input_format_arrow_use_native_reader` and `output_format_arrow_use_native_writer` default to true, so the native reader/writer handle the `Arrow` and `ArrowStream` formats by default, and add a transparent fallback to the Apache Arrow library reader for the cases the native reader does not reproduce faithfully, so existing behaviour is preserved everywhere. `ArrowIPCBlockInputFormat` (and `ArrowIPCSchemaReader`) delegate to `ArrowBlockInputFormat` / `ArrowSchemaReader` when, after parsing the schema, they detect: - GeoParquet geometry columns (schema-level `geo` metadata), - union columns (Variant), - `import_nested` Nested flattening (a dotted header column backed by a List/Struct/Map field, which also covers case-insensitive nested matching), - a nullable Arrow column read into a non-nullable ClickHouse column under `input_format_null_as_default` (the library applies the column's DEFAULT expression). The stream is rewound for the fallback with a `PeekableReadBuffer` (checkpoint around the schema read); the file format re-seeks to the start. Also: reject non-unique LowCardinality dictionaries with INCORRECT_DATA, matching the library. With native as the default, the full existing Arrow stateless test suite passes (the only remaining failures are pre-existing, environment-specific issues unrelated to this change: a parquet test timeout, a `user_files` permission error, and a wasm test). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…e library fallback (P11) The native `Arrow`/`ArrowStream` reader and writer previously delegated to the Apache Arrow C++ library for a few cases (`ArrowBlockInputFormat`/`ArrowSchemaReader` and the output format). Implement all of those natively and remove the fallback entirely: - Variant <-> Union: decode an Arrow dense/sparse union into `ColumnVariant` and encode `ColumnVariant` as an Arrow dense union (a types and an offsets buffer plus a trailing single-element `null` child for NULL rows; no validity buffer). `fieldToCHType` and the schema writer now map `Union` <-> `Variant`. The library never read unions, so this also adds union reading. `RecordBatchEncoder::canNativelyEncode` accepts `Variant`. - GeoParquet: parse the schema-level `geo` metadata and decode WKB/WKT binary columns into the geo types via `parseGeoMetadataEncoding` / `parseWKBFormat` / `appendObjectToGeoColumn`, gated by `input_format_parquet_allow_geoparquet_parser`. Corrupted offsets are rejected with `INCORRECT_DATA` by the existing string-buffer bounds checks. - `import_nested` and case-insensitive matching: mirror the library's column-matching driver in `buildChunk` using `Nested::extractTableName` / `Nested::collect` / `NestedColumnExtractHelper`, reshaping the decoded `Array(Tuple(...))` to the collected `Nested` type so it can be flattened into dotted subcolumns. - `input_format_null_as_default`: call the shared `insertNullAsDefaultIfNeeded` (handles nested narrowing and records `BlockMissingValues` so the engine applies column DEFAULTs). - Dictionary-encoded output (`output_format_arrow_low_cardinality_as_dictionary`): accumulate one dictionary per id across record batches (extending it via Arrow dictionary deltas), write `DictionaryBatch` messages, record dictionary blocks in the file footer, and write the record batch with the integer index column. The index type honours `output_format_arrow_use_signed_indexes_for_dictionary` / `output_format_arrow_use_64_bit_indexes_for_dictionary`. The only remaining use of the library writer is for column types the native encoder does not support at all (e.g. `Dynamic`/`JSON`), which is a capability guard rather than a fallback for the features above. Removed `needsLibraryFallback`, the schema-reader fallback, the `PeekableReadBuffer`/`fallback` members, and the `friend class ArrowIPCBlockInputFormat`. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…library (P12) Benchmarking the native reader/writer against the Apache Arrow library revealed several cases where native was slower; fix them so native is faster (or at parity for raw bulk writes) everywhere. - Dictionary write (`output_format_arrow_low_cardinality_as_dictionary`): deduplicate at the dictionary level (a handful of values) via the LowCardinality column's existing dictionary, instead of materializing the full column and hashing every row. ~12x faster for that case (now faster than the library). - Dictionary read: build the `LowCardinality` column directly from (keys, indexes) via `insertRangeFromDictionaryEncodedColumn` — no full-column gather and no re-deduplication. ~5x faster (now faster than the library). - Body (de)compression: like the Apache Arrow writer (whose codec is multi-threaded), compress and decompress the record-batch buffers in parallel across the shared format thread pool, and reuse one codec context across all buffers (LZ4 frame via `LZ4F_compressBegin/Update/End` with a 4 MB block size, ZSTD via a reused `ZSTD_CCtx`/`ZSTD_DCtx`) instead of allocating a context per buffer. Turns a ~4x compression slowdown into a win for everything except raw numeric bulk write (at parity). - Fixed-width encoding: append the column's contiguous data straight into the body, removing a redundant per-buffer copy. Output remains byte-compatible: native-written LZ4/ZSTD is read correctly by the Apache Arrow library and by pyarrow, and native reads the library's output (cross-checked across the full type matrix and both formats). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Resolve the conflict in `ArrowBlockOutputFormat.cpp`: keep the native `canNativelyEncodeBlock` capability check alongside master's added forward declaration of `registerOutputFormatArrow`. Sync the `NuRaft` and `mariadb-connector-c` submodules bumped on master. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…elines-init-variables Master's `.clang-tidy` enables `cppcoreguidelines-init-variables` (warnings as errors). Initialize the local scalars that are subsequently filled via `memcpy`/`readStrict` in the native Arrow IPC reader/writer so the `ClangTidy` CI check passes; no behavior change. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Workflow [PR], commit [5e5bbdc] Summary: ✅
AI ReviewSummaryThis PR replaces the Apache Arrow C++ conversion path for Final Verdict
|
CI report: #106522 - Style check: use Allman braces for the `make_int` lambda in `SchemaConverter.cpp`; remove the now-unused `NOT_IMPLEMENTED` `ErrorCodes` declaration from `ArrowIPCBlockInputFormat.cpp` (left over after removing the library fallback). - ClangTidy (`cppcoreguidelines-init-variables`): initialize `make_nullable` in `ArrowIPCSchemaReader.cpp`. - Fast test: tag the new `04314`-`04319` Arrow IPC tests with `# Tags: no-fasttest`, matching the existing Arrow tests (the Fast test build has no Arrow support, so the formats are unavailable there). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ase value A delta dictionary batch appends to the existing dictionary, but it was only checked for internal duplicate values per incoming batch. A unique base dictionary plus a unique delta can still produce a duplicate merged value (e.g. base `['a', 'b']` followed by a delta `['b']`), which violates the `LowCardinality` dictionary uniqueness invariant the non-delta path enforces and differs from the Apache Arrow library reader. Both dictionary-batch sites (the file reader and the stream reader) now re-validate the merged dictionary with `checkDictionaryUnique` after a delta is applied, so a delta that repeats a base value is rejected with the same `Arrow dictionary contains duplicate values` error as the non-delta path. Addresses the second Major of the AI review on #106522. New test `04497_native_arrow_ipc_delta_dictionary_duplicate`: a base dictionary `['AAA', 'BBB']` followed by a delta whose only value is patched from `'CCC'` to `'AAA'` (the test asserts a delta — not a replacement — was emitted) makes the merged dictionary repeat `'AAA'`; the read is now rejected. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Pushed MergeThe Major 1 — record-batch layout exactness on the non-pruned path (
|
CI triage (head
|
CI triage update (head
|
|
@alexey-milovidov This upgrade-check #108651 replaces the old per-literal So the On a tracking issue: we chose the allow-list fix (#108651) over a standalone issue. Opening a GitHub issue on our side needs human approval, so I have not filed one. If you would prefer a tracked issue in addition to the fix, say so and I will open one. #108651 is approved and |
The new `native_arrow_ipc` performance test failed the `Performance Comparison` job (`amd_release` 3/6 and `arm_release` 6/6), which made `Mergeable Check` and the overall `PR` check red. Two independent problems, both self-contained in the test: 1. The write benchmark used `SELECT * FROM na_src FORMAT Arrow`, which does not measure Arrow encoding at all. The perf runner drives queries over the native TCP protocol (`clickhouse_driver`), which ignores the query's `FORMAT` clause and sends `Native` blocks back to the client, so the query really measured client-side row deserialization of 20M rows (~58s) instead of the encoder. That blew past the 15s `max_execution_time` of a measured run (`Code: 159 Timeout exceeded`) and aborted the whole test. Verified with `clickhouse_driver`: `FORMAT Arrow` (2.71s) is identical to a plain `SELECT *` (2.69s) and unlike `FORMAT Null` (0.018s). The encode is now measured by `INSERT INTO na_arrow_out SELECT * FROM na_src` where `na_arrow_out` is `File(Arrow, '/dev/null')` — the encoder runs server-side and the output is discarded — the same idiom used by `select_format.xml`. 2. Every query pinned `input_format_arrow_use_native_reader` / `output_format_arrow_use_native_writer`, which are added by this pull request and therefore do not exist on the compared master server. The prewarm on that server failed with `Code: 115 ... is neither a builtin setting`, and any non-empty per-test `*-err.log` is folded into `run-errors.tsv`, which `report.py` counts unconditionally as an error and fails the job. The queries now run on the default path (native on this branch, the Apache Arrow library on master), so nothing errors on the reference server and the comparison directly measures the speedup of this change. Validated end to end through `tests/performance/scripts/perf.py`: exit code 0, empty `err.log`, write ~1.70s and read ~1.10s per run for 20M rows on the library path, both far under the limit (native is faster still). CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106522&sha=5d9447cb8cea70d101d8e3f1683402b07ec84440&name_0=PR PR: #106522 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Two recently-added stateless tests exercise Arrow behavior that the Apache-Arrow-library path gained on `master` but the native reader/writer (now the default) did not yet implement, so they failed once the native path became the default after the latest `master` merge: - `04209_arrow_time_import_export` (issue #104038): mapping between ClickHouse `Time`/`Time64` and Arrow `time32`/`time64`. - `03926_arrow_fixed_offset_timezone` (issue #73261): reading Arrow timestamps whose timezone is a fixed numeric UTC offset (`+05:30`, `-08:00`) or the non-IANA `fixed` marker. `Time`/`Time64` support (writer and reader), mirroring the library path: - Writer schema (`SchemaConverter::buildField`): `Time` maps to Arrow `time32[s]`; `Time64(scale)` maps to `time32` (SECOND/MILLISECOND) for scale <= 3, else `time64` (MICROSECOND/NANOSECOND). - Writer values (`RecordBatchEncoder::encodeValues`): `Time` writes the Int32 seconds directly; `Time64` rescales the value up to the Arrow unit's scale and range-checks the 32-bit path, raising `DECIMAL_OVERFLOW` on overflow, matching `fillArrowArrayWithTime64ColumnData`. - Reader type (`SchemaConverter::fieldToCHType`): Arrow `time32`/`time64` maps to `Time64(unit * 3)` (previously `DateTime64`, which is wrong -- `Time` carries no timezone, so a non-UTC session timezone must not shift the stored value on import). - Reader values (`RecordBatchDecoder`): a `Time` field now fills a `ColumnDecimal<Time64>` (`time32` = 4-byte, `time64` = 8-byte). Fixed-offset timezone support (reader): `fieldToCHType` normalizes an Arrow timestamp's timezone with `normalizeArrowTimezone` before building `DataTypeDateTime64` -- a full `[+|-]HH:MM[:SS]` offset becomes cctz's canonical `Fixed/UTC+HH:MM:SS`, `fixed` becomes `UTC`, and anything else is passed through unchanged so a genuinely-malformed zone still raises `Cannot load time zone`. This mirrors the helper of the same name in the library reader (`ArrowColumnToCHColumn.cpp`). Both tests pass locally with the native reader/writer as the default, and the full native Arrow IPC suite (32 tests) still passes. Related: #104038 Related: #73261 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ormat # Conflicts: # src/Processors/Formats/Impl/ArrowBlockInputFormat.cpp
…IPC reader The native reader only reinterpreted a top-level fixed_size_binary column as UUID / big integer. It now recognises the same raw-byte conversions the Apache Arrow library reader does, closing two gaps: - Variable-width `Binary` (not just `fixed_size_binary`) is reinterpreted as `IPv6` / `Int128` / `UInt128` / `Int256` / `UInt256`, matching `readIPv6ColumnFromBinaryData` / `readColumnWithBigNumberFromBinaryData`: null rows are skipped in the width check, and if any non-null row is not exactly the target width the column is left as `String` for the cast (rather than failing). - The conversions are applied recursively through `Nullable`, `Array`, `Tuple` and `Map`, so nested shapes such as `Array(Int128)` (from `list<fixed_size_binary[16]>`) and `Tuple(ip IPv6)` (from `struct<ip: binary>`) are reinterpreted instead of being decoded as `FixedString`/`String` children and text-parsed by the cast. `IPv6` is also handled from `fixed_size_binary(16)`, which the ClickHouse writer emits, so that round-trip no longer relies on text parsing. Also adapts the geo call site to the merged `parseWKTFormat` signature (`precise_float_parsing`). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
The master merge in this branch (
Root cause: in the native reader, I did not push anything — leaving the fix to you since it touches the decode path you are iterating on. The new raw-byte test |
…ive Arrow IPC reader Schema inference and decoding of a nullable Arrow `Struct` wrapped it in `Nullable(Tuple(...))` unconditionally, so with the default settings `DESCRIBE` returned a type that `CREATE TABLE` rejects and `SELECT *` produced `NULL` for null-struct rows. Wrap a `Struct` (`Tuple`) in `Nullable` only when `allow_experimental_nullable_tuple_type` is enabled (via `schema_inference_allow_nullable_tuple_type`), matching the Apache Arrow library reader's `allow_nullable_struct` gate. Otherwise the struct is read as a plain `Tuple` with the struct-level null map dropped (its element values are kept), as it worked before `Nullable(Tuple)` was supported. `fieldToCHType` and `decodeField` apply the same gate so the inferred type and the decoded column stay consistent. Fixes 04493_nullable_tuple_schema_inference_arrow_formats on the native reader. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Confirmed the two-part root cause and validated the fix in Root cause, as you described:
Local validation (both directions):
Session id: cron:clickhouse-worker-slot-3:20260707-150700 |
…ve Arrow IPC reader The struct-into-Nullable gate only checked `allow_experimental_nullable_tuple_type`, but the library reader also enables `Nullable(Tuple(...))` when the requested target type is already nullable. So reading Arrow data with the setting off into an existing `Nullable(Tuple)` column (or nested `Array(Nullable(Tuple))`) dropped the struct-level null map and decoded the child payload as a real value row instead of `NULL`. `decodeField` now wraps a struct in Nullable when the setting is on OR the effective target hint at this field is nullable (matching the library's `allow_nullable_struct`), resolving the hint via `resolveTargetHint` so both top-level and nested fields honor it. `decodeColumns` reconciles the reported type with the decoded column via `matchColumnNullability`, so the column/type pair stays consistent when `decodeField` wraps a struct that `fieldToCHType` (setting-only) left as a plain Tuple. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 2859/3219 (88.82%) · Uncovered code |

Implement a native ClickHouse reader and writer for the
ArrowandArrowStreamformats that does not use the Apache Arrow C++ library. It parses the Arrow IPC metadata (FlatBuffers) directly and decodes/encodes record-batch buffers straight to and from ClickHouse columns, eliminating the extra full materialization into Arrow's array layer (builders, memory pool, codec stack) on each side of the conversion. Parquet and ORC keep using the Apache Arrow library.The native implementation is now the default, controlled by the new settings
input_format_arrow_use_native_readerandoutput_format_arrow_use_native_writer; setting them to0selects the previous Apache-Arrow-library path. It has full type parity with the library path — includingNullable,Array/Tuple/Map,LowCardinality↔ Arrow dictionary (incl. dictionary-encoded output with deltas),UUID/IPv4/IPv6/big integers/Interval,Variant↔ Arrow union,Nestedflattening / case-insensitive matching,input_format_null_as_default, GeoParquet (WKB/WKT), and LZ4_FRAME / ZSTD body compression — and there is no library fallback.Motivation: remove excess copies and conversions and make these formats faster. Benchmarked against the Apache Arrow library across numeric / string / nullable / LowCardinality / array data, both formats, and
none/lz4_frame/zstdcompression: native is faster for reading in every case and for writing in every case except raw fixed-width numeric bulk writes, which are at parity. Output stays byte-compatible — native-written LZ4/ZSTD data is read correctly by the Apache Arrow library and by pyarrow, and native reads the library's output.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Implemented a native reader and writer for the
ArrowandArrowStreamformats that does not use the Apache Arrow library, avoiding extra data copies and conversions. It is now the default (settingsinput_format_arrow_use_native_readerandoutput_format_arrow_use_native_writer) and is faster for both reading and writing.Version info
26.7.1.695(included in26.7and later)