Skip to content

Support Nullable(Tuple) for Arrow, ArrowStream, ORC, legacy Parquet formats - #101272

Merged
nihalzp merged 38 commits into
ClickHouse:masterfrom
nihalzp:support-arrow-orc-nullable-tuple
Apr 15, 2026
Merged

nihalzp merged 38 commits into
ClickHouse:masterfrom
nihalzp:support-arrow-orc-nullable-tuple

Conversation

@nihalzp

@nihalzp nihalzp commented Mar 30, 2026 •

Copy link
Copy Markdown
Member

The following queries now work.

-- Setup
SET allow_experimental_nullable_tuple_type = 1;
SET engine_file_truncate_on_insert = 1;

Arrow

INSERT INTO TABLE FUNCTION file('test.arrow', 'Arrow', 'c0 Nullable(Tuple(UInt32, String))') VALUES ((1, 'a')), (NULL), ((3, 'c'));
SELECT c0 FROM file('test.arrow', 'Arrow', 'c0 Nullable(Tuple(UInt32, String))');

Arrow

INSERT INTO TABLE FUNCTION file('test.arrowstream', 'ArrowStream', 'c0 Nullable(Tuple(UInt32, String))') VALUES ((1, 'a')), (NULL), ((3, 'c'));
SELECT c0 FROM file('test.arrowstream', 'ArrowStream', 'c0 Nullable(Tuple(UInt32, String))');

ORC

INSERT INTO TABLE FUNCTION file('test.orc', 'ORC', 'c0 Nullable(Tuple(UInt32, String))') VALUES ((1, 'a')), (NULL), ((3, 'c'));
SELECT c0 FROM file('test.orc', 'ORC', 'c0 Nullable(Tuple(UInt32, String))');

Legacy Parquet (Arrow-based reader):

INSERT INTO TABLE FUNCTION file('test.parquet', 'Parquet', 'c0 Nullable(Tuple(UInt32, String))') VALUES ((1, 'a')), (NULL), ((3, 'c'));
SELECT c0 FROM file('test.parquet', 'Parquet', 'c0 Nullable(Tuple(UInt32, String))') SETTINGS input_format_parquet_use_native_reader_v3 = 0;

Changelog category (leave one):

  • Improvement

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

Support Nullable(Tuple) for Arrow, ArrowStream, ORC, legacy Parquet formats.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.4.1.978

@clickhouse-gh

clickhouse-gh Bot commented Mar 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7d950a7]

Summary: ✅


AI Review

Summary

This PR adds support for Nullable(Tuple(...)) round-trips in Arrow, ArrowStream, ORC, and legacy Parquet, including null-map propagation for nested tuple elements and broader stateless coverage. The core implementation looks solid, but one important edge-case remains under-tested: reading with LowCardinality(Nullable(Tuple(...))) type hints. Verdict: request changes until this gap is covered.

Missing context
  • ⚠️ No CI report/log links were provided in the review request, so I could not validate runtime regressions/failures beyond code and tests in this checkout.
Findings
  • ⚠️ Majors
    • [tests/queries/0_stateless/04064_tuple_inside_nullable_arrow_orc_roundtrip.sql:1+, tests/queries/0_stateless/04065_tuple_inside_nullable_parquet_roundtrip.sql:1+] Regression coverage still misses LowCardinality(Nullable(Tuple(...))) read-hint scenarios.
    • Impact: current changes explicitly touch LowCardinality + nullable handling paths; without dedicated tests this can silently regress.
    • Suggested fix: add at least one read-hint case per affected reader path (Arrow/ArrowStream/ORC and legacy Parquet) with LowCardinality(Nullable(Tuple(...))), including rows with both struct-level NULL and inner nullable values.
Tests
  • ⚠️ Add regression tests for LowCardinality(Nullable(Tuple(...))) read hints across updated readers to lock in the behavior this PR targets.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    • Add targeted regression coverage for LowCardinality(Nullable(Tuple(...))) read-hint paths in the new format tests.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Mar 30, 2026
@nihalzp
nihalzp requested a review from Avogar March 30, 2026 21:55
Comment thread src/DataTypes/NestedUtils.cpp Resolved
@Avogar Avogar self-assigned this Apr 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.00% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 97.87% (138/141) · Uncovered code

Full report · Diff report

@nihalzp
nihalzp added this pull request to the merge queue Apr 15, 2026
Merged via the queue into ClickHouse:master with commit fc17de3 Apr 15, 2026
161 checks passed
@nihalzp
nihalzp deleted the support-arrow-orc-nullable-tuple branch April 15, 2026 17:21
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 15, 2026
zvonand added a commit to Altinity/ClickHouse that referenced this pull request May 17, 2026
The cherry-pick of upstream PR ClickHouse#101272 added test
`04019_formats_nullable_empty_tuple_roundtrip` (which exercises
`MsgPack` with `Nullable(Tuple())`) but missed the matching change to
`MsgPackVisitor::start_array` from upstream commit acf7821. As a
result the `SELECT` half of the `MsgPack` roundtrip throws
`ILLEGAL_COLUMN: Cannot insert MessagePack array into column with type
Nullable(Tuple())`.

Apply the upstream fix verbatim: unwrap the `Nullable` before
dispatching on `isTuple`, mark the row non-null in the null map, and
descend into the inner `ColumnTuple`.

Addresses 1 failing test in Stateless tests (amd_asan, distributed
plan, parallel, 1/4) on #1802.

Failure report:
https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=1802&sha=4dccbce9dfb174c622d7a6cd95a7aba252e20e9f&name_0=PR&name_1=Stateless%20tests%20%28amd_asan%2C%20distributed%20plan%2C%20parallel%2C%201%2F4%29

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zvonand pushed a commit to Altinity/ClickHouse that referenced this pull request May 18, 2026
…solution in next commit)

---
Original cherry-pick message follows:

Merge pull request ClickHouse#101272 from nihalzp/support-arrow-orc-nullable-tuple

Support `Nullable(Tuple)` for `Arrow`, `ArrowStream`, `ORC`, legacy `Parquet` formats
zvonand added a commit to Altinity/ClickHouse that referenced this pull request May 18, 2026
zvonand added a commit to Altinity/ClickHouse that referenced this pull request May 18, 2026
The cherry-pick of upstream PR ClickHouse#101272 added test
`04019_formats_nullable_empty_tuple_roundtrip` (which exercises
`MsgPack` with `Nullable(Tuple())`) but missed the matching change to
`MsgPackVisitor::start_array` from upstream commit acf7821. As a
result the `SELECT` half of the `MsgPack` roundtrip throws
`ILLEGAL_COLUMN: Cannot insert MessagePack array into column with type
Nullable(Tuple())`.

Apply the upstream fix verbatim: unwrap the `Nullable` before
dispatching on `isTuple`, mark the row non-null in the null map, and
descend into the inner `ColumnTuple`.

Addresses 1 failing test in Stateless tests (amd_asan, distributed
plan, parallel, 1/4) on #1802.

Failure report:
https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=1802&sha=4dccbce9dfb174c622d7a6cd95a7aba252e20e9f&name_0=PR&name_1=Stateless%20tests%20%28amd_asan%2C%20distributed%20plan%2C%20parallel%2C%201%2F4%29

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zvonand added a commit to Altinity/ClickHouse that referenced this pull request May 19, 2026
The cherry-pick of upstream PR ClickHouse#101272 added tests
`04019_formats_nullable_empty_tuple_roundtrip` and
`04064_tuple_inside_nullable_arrow_orc_roundtrip` (which exercise
`Arrow`/`ArrowStream` roundtrip of `Nullable(Tuple(...))`) but missed
the matching change to `fillArrowArrayWithTupleColumnData` from
upstream commit `1e5b4344275` ("Add `Nullable(Tuple)` Arrow writing
support"). As a result, the Arrow writer ignored the struct-level null
bytemap: `NULL` rows roundtripped as default-valued tuples (`()`
instead of `\N`, `((0,''),0)` instead of `((NULL,20))`, etc.).

Apply the upstream fix verbatim: pass `nullptr` for the children's
null bytemap (struct-level and child-level nulls are independent in
Arrow) and use `builder.AppendNull` for null struct rows.

Addresses failing tests in `Stateless tests (amd_asan, distributed
plan, parallel, 1/4)`, `Stateless tests (amd_asan, distributed plan,
parallel, 3/4)`, `Stateless tests (amd_debug, parallel)`, and
`Stateless tests (arm_binary, parallel)` on
#1802.

Failure report:
https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=1802&sha=e77fa9f7de8f967c20e9e55efa8be5ac4e5bb482&name_0=PR

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zvonand added a commit to Altinity/ClickHouse that referenced this pull request May 19, 2026
`CSVFormatReader::readField` treats an empty unquoted field as the
default value when `input_format_csv_empty_as_default` is enabled (the
default). For a `Nullable(Tuple())` column the default is `NULL`, so
the empty-tuple values written by `SerializationTuple::serializeTextCSV`
(which produces an empty field for a tuple with zero elements) are
read back as `NULL` instead of `()`. This breaks the
`04019_formats_nullable_empty_tuple_roundtrip` test added in the
cherry-pick of upstream PR ClickHouse#101272.

The fix is the same as upstream commit `29f6f23cafe` from upstream PR
\ClickHouse#100038 ("Fix `Nullable(Tuple)` not working with `CSV`, `MsgPack` format
properly"), which ClickHouse#101272 depends on: special-case
`Nullable(Tuple())` (zero-element tuple) so the empty field falls
through to normal deserialization instead of being replaced with
`NULL`. Applied verbatim (diff matches upstream byte-for-byte).

Addresses CSV section failure in test
`04019_formats_nullable_empty_tuple_roundtrip` on
#1802.

Failure report:
https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=1802&sha=36ae78193451a1aaf81d238b7b3bcb25fab3ee3d&name_0=PR&name_1=Stateless+tests+%28amd_asan%2C+distributed+plan%2C+parallel%2C+1%2F4%29&name_2=Tests

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
subkanthi pushed a commit to Altinity/ClickHouse that referenced this pull request May 26, 2026
…solution in next commit)

---
Original cherry-pick message follows:

Merge pull request ClickHouse#101272 from nihalzp/support-arrow-orc-nullable-tuple

Support `Nullable(Tuple)` for `Arrow`, `ArrowStream`, `ORC`, legacy `Parquet` formats
subkanthi pushed a commit to Altinity/ClickHouse that referenced this pull request May 26, 2026
subkanthi pushed a commit to Altinity/ClickHouse that referenced this pull request May 26, 2026
The cherry-pick of upstream PR ClickHouse#101272 added test
`04019_formats_nullable_empty_tuple_roundtrip` (which exercises
`MsgPack` with `Nullable(Tuple())`) but missed the matching change to
`MsgPackVisitor::start_array` from upstream commit acf7821. As a
result the `SELECT` half of the `MsgPack` roundtrip throws
`ILLEGAL_COLUMN: Cannot insert MessagePack array into column with type
Nullable(Tuple())`.

Apply the upstream fix verbatim: unwrap the `Nullable` before
dispatching on `isTuple`, mark the row non-null in the null map, and
descend into the inner `ColumnTuple`.

Addresses 1 failing test in Stateless tests (amd_asan, distributed
plan, parallel, 1/4) on #1802.

Failure report:
https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=1802&sha=4dccbce9dfb174c622d7a6cd95a7aba252e20e9f&name_0=PR&name_1=Stateless%20tests%20%28amd_asan%2C%20distributed%20plan%2C%20parallel%2C%201%2F4%29

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
subkanthi pushed a commit to Altinity/ClickHouse that referenced this pull request May 26, 2026
The cherry-pick of upstream PR ClickHouse#101272 added tests
`04019_formats_nullable_empty_tuple_roundtrip` and
`04064_tuple_inside_nullable_arrow_orc_roundtrip` (which exercise
`Arrow`/`ArrowStream` roundtrip of `Nullable(Tuple(...))`) but missed
the matching change to `fillArrowArrayWithTupleColumnData` from
upstream commit `1e5b4344275` ("Add `Nullable(Tuple)` Arrow writing
support"). As a result, the Arrow writer ignored the struct-level null
bytemap: `NULL` rows roundtripped as default-valued tuples (`()`
instead of `\N`, `((0,''),0)` instead of `((NULL,20))`, etc.).

Apply the upstream fix verbatim: pass `nullptr` for the children's
null bytemap (struct-level and child-level nulls are independent in
Arrow) and use `builder.AppendNull` for null struct rows.

Addresses failing tests in `Stateless tests (amd_asan, distributed
plan, parallel, 1/4)`, `Stateless tests (amd_asan, distributed plan,
parallel, 3/4)`, `Stateless tests (amd_debug, parallel)`, and
`Stateless tests (arm_binary, parallel)` on
#1802.

Failure report:
https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=1802&sha=e77fa9f7de8f967c20e9e55efa8be5ac4e5bb482&name_0=PR

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
subkanthi pushed a commit to Altinity/ClickHouse that referenced this pull request May 26, 2026
`CSVFormatReader::readField` treats an empty unquoted field as the
default value when `input_format_csv_empty_as_default` is enabled (the
default). For a `Nullable(Tuple())` column the default is `NULL`, so
the empty-tuple values written by `SerializationTuple::serializeTextCSV`
(which produces an empty field for a tuple with zero elements) are
read back as `NULL` instead of `()`. This breaks the
`04019_formats_nullable_empty_tuple_roundtrip` test added in the
cherry-pick of upstream PR ClickHouse#101272.

The fix is the same as upstream commit `29f6f23cafe` from upstream PR
\ClickHouse#100038 ("Fix `Nullable(Tuple)` not working with `CSV`, `MsgPack` format
properly"), which ClickHouse#101272 depends on: special-case
`Nullable(Tuple())` (zero-element tuple) so the empty field falls
through to normal deserialization instead of being replaced with
`NULL`. Applied verbatim (diff matches upstream byte-for-byte).

Addresses CSV section failure in test
`04019_formats_nullable_empty_tuple_roundtrip` on
#1802.

Failure report:
https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=1802&sha=36ae78193451a1aaf81d238b7b3bcb25fab3ee3d&name_0=PR&name_1=Stateless+tests+%28amd_asan%2C+distributed+plan%2C+parallel%2C+1%2F4%29&name_2=Tests

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Aug 10, 2026
Since ClickHouse#101272 the Arrow reader wraps a nullable struct as `Nullable(Tuple(...))`
instead of a plain `Tuple(...)`. `Nested::flatten` only descends into a plain
`DataTypeTuple`, so reading a flattened subcolumn such as `s.v` off such a column
returned column defaults instead of the nested data.

`NestedColumnExtractHelper` now unwraps the nullable tuple before flattening,
propagating the struct null map down to each element. The propagation is
schema-driven: the resulting element types depend only on the declared types and
never on the null map contents, so an empty sample block (schema planning, e.g.
`StorageHive::read`) plans the same types as a data block that carries nulls.

The `allow_nullable_tuple_in_extracted_subcolumns` policy is applied once, at the
terminal extraction point. A `Nullable(Tuple)` reaching it can be either synthetic
(from an outer struct null map) or declared nullable in the schema, and the null map
contents cannot tell those apart, so the arbiter is the root declared type's
subcolumn type: a declared `Nullable` stays nullable so real NULLs survive, while a
synthetic wrapping follows the setting. That lookup is matched case-insensitively on
both sides, since the Arrow/ArrowIPC/ORC readers lowercase the requested name while
`StorageHive::read` passes the caller's spelling through unchanged.

Also fixes the native Arrow IPC reader, which cast a top-level struct to the type
`Nested::collect` returns for a scalar-subcolumn set (the leaf type) and threw
`toInt32(Tuple)`, and an empty `Nullable(Tuple())`, where unwrapping tried to build
a `ColumnTuple` with no elements.

Closes: ClickHouse#109726
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants