Skip to content

Fix Nullable(Tuple) not working with CSV, MsgPack format properly - #100038

Merged
Avogar merged 8 commits into
ClickHouse:masterfrom
nihalzp:fix-csv-empty-nullable-empty-tuple
Mar 19, 2026
Merged

Avogar merged 8 commits into
ClickHouse:masterfrom
nihalzp:fix-csv-empty-nullable-empty-tuple

Conversation

@nihalzp

@nihalzp nihalzp commented Mar 19, 2026 •

Copy link
Copy Markdown
Member

Given,

SET allow_experimental_nullable_tuple_type = 1;
SET engine_file_truncate_on_insert = 1;

CREATE TABLE test_nullable_empty_tuple (c0 Nullable(Tuple())) ENGINE = Memory;
INSERT INTO TABLE test_nullable_empty_tuple (c0) VALUES (()), (NULL), (());

CSV:

INSERT INTO TABLE FUNCTION file(currentDatabase() || '_04019.csv', 'CSV', 'c0 Nullable(Tuple())') SELECT c0 FROM test_nullable_empty_tuple;
-- returns \N \N \N. Should be () \N ()
SELECT c0 FROM file(currentDatabase() || '_04019.csv', 'CSV', 'c0 Nullable(Tuple())');

MsgPack:

SET allow_experimental_nullable_tuple_type = 1;
SET engine_file_truncate_on_insert = 1;

CREATE TABLE test_single (c0 Nullable(Tuple(Int32))) ENGINE = Memory;
INSERT INTO test_single VALUES ((1)), (NULL), ((3));
INSERT INTO TABLE FUNCTION file(currentDatabase() || '_04029_single.msgpack', 'MsgPack', 'c0 Nullable(Tuple(Int32))') SELECT c0 FROM test_single;

-- Throws error but should work
SELECT c0 FROM file(currentDatabase() || '_04029_single.msgpack', 'MsgPack', 'c0 Nullable(Tuple(Int32))');

This PR contains test for other formats as well to make sure they work with empty Nullable(Tuple).

TODO: Currently, Arrow, ArrowStream, and ORC still have problem with Nullable(Tuple) which I will fix later in subsequent PR.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix CSV, MsgPack format not being able to parse Nullable(Tuple) properly. Closes #99753.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.3.1.890

@clickhouse-gh

clickhouse-gh Bot commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e1c67a3]

Summary: ✅

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 19, 2026
@nihalzp
nihalzp requested a review from Avogar March 19, 2026 14:17
@clickhouse-gh

clickhouse-gh Bot commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.80% 83.80% +0.00%
Functions 23.90% 23.90% +0.00%
Branches 76.30% 76.30% +0.00%

PR changed lines: PR changed-lines coverage: 97.50% (39/40, 0 noise lines excluded)
Diff coverage report
Uncovered code

@Avogar Avogar self-assigned this Mar 19, 2026
@Avogar
Avogar added this pull request to the merge queue Mar 19, 2026
Merged via the queue into ClickHouse:master with commit 59b29fe Mar 19, 2026
159 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 Mar 19, 2026
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
`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 Jun 30, 2026
…of NULL

Since Nullable(Tuple) is now serialized as a single quoted CSV field
("()"), the empty-tuple value no longer produces an empty field, so the
is_nullable_empty_tuple exception in CSVFormatReader::readField (added in
PR ClickHouse#100038 for the old separate-columns serialization) is obsolete. With
input_format_csv_empty_as_default = 1 (the default) it forced an empty
field through SerializationTuple::deserializeText, which expects '(' and
threw CANNOT_PARSE_INPUT_ASSERTION_FAILED instead of inserting the
nullable default. Remove the exception so an empty field for
Nullable(Tuple()) becomes NULL, consistent with Nullable(Tuple(T)) and
every other Nullable type. The "()" / "(5)" quoted fields still parse
back to the tuple value.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…of NULL

Since Nullable(Tuple) is now serialized as a single quoted CSV field
("()"), the empty-tuple value no longer produces an empty field, so the
is_nullable_empty_tuple exception in CSVFormatReader::readField (added in
PR ClickHouse#100038 for the old separate-columns serialization) is obsolete. With
input_format_csv_empty_as_default = 1 (the default) it forced an empty
field through SerializationTuple::deserializeText, which expects '(' and
threw CANNOT_PARSE_INPUT_ASSERTION_FAILED instead of inserting the
nullable default. Remove the exception so an empty field for
Nullable(Tuple()) becomes NULL, consistent with Nullable(Tuple(T)) and
every other Nullable type. The "()" / "(5)" quoted fields still parse
back to the tuple value.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default 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.

Empty nullable tuples read back as null values

3 participants