Repository navigation
Conversation
A Nullable(Tuple(...)) had a row-dependent CSV width: a NULL row wrote a single \N field, while a non-null row was flattened into separate columns (N fields) under output_format_csv_serialize_tuple_into_separate_columns. The CSVWithNames(AndTypes) header was flattened to N columns, matching only the non-null rows, so NULL rows desynced the column count and the data did not round-trip (CANNOT_PARSE_INPUT). Keep a Nullable(Tuple) as a single quoted CSV value (it is not flattened), so every row is exactly one field and the header stays one cell. A bare Tuple (not wrapped in Nullable) is still flattened as before. Input is made symmetric so the value round-trips. Follow-up to ClickHouse#107371, reported by Avogar. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260630-142700 |
|
cc @Avogar @al13n321 — could you review? Follow-up to #107371: a |
|
Workflow [PR], commit [65f1c79] Summary: ✅
AI ReviewSummaryThis PR makes Final Verdict
|
…eTuple clang-tidy bugprone-return-const-ref-from-parameter (warnings-as-errors in the arm_tidy build) flagged adjustCSVSettingsForNullableTuple returning a const FormatSettings & that, on the fast path, aliases the by-const-ref parameter, which can dangle if the argument is a temporary. Make the helper fill the std::optional<FormatSettings> out-parameter only, and bind the effective settings reference at each call site. The common Nullable(scalar) path still does no copy (storage stays empty); only the Nullable(Tuple) path copies, exactly as before. No behavior change. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…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]>
|
Addressing the Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-4:20260630-180000 |
…ple-separate-columns-107342 # Conflicts: # src/Processors/Formats/Impl/CSVRowInputFormat.cpp
|
Follow-up validation gate for 640f4a6 (2nd bot change request + master merge conflict resolution). Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-4:20260630-185900 |
|
The issue has been fixed, this PR can be closed |
The single-field output change stopped the reader from accepting the legacy separate-columns CSV encoding older versions emitted for non-null Nullable(Tuple) rows (e.g. 1,"a" for Nullable(Tuple(ID UInt64, Name String))). On input, when input_format_csv_deserialize_separate_columns_into_tuple = 1, try the new single quoted-field encoding first (also handles the \N NULL field) and, on a parse failure, roll back and read the legacy separate-columns encoding. Output stays the single-field form. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Addressed in d9d0a10. Input now accepts BOTH encodings for Verified both directions on a debug build: your example |
CI finish ledger — d9d0a10CI fully finished (Finish Workflow + Mergeable Check pass). No failed checks on this head; every job is pass or skipping.
Session id: cron:our-pr-ci-monitor:20260708-163000 |
Avogar
left a comment
There was a problem hiding this comment.
I don't think we should support old case with separate tuple elements if type is Nullable(Tuple), because it still leads to ambiguity on first \N. Let's just say that Nullable(Tuple) cannot be parsed/serialized as separate columns in CSV in the setting description
…input Per review, do not support the legacy separate-columns encoding for Nullable(Tuple) on input: a leading \N field is ambiguous (outer NULL of the tuple vs NULL of its first element), so accepting both encodings cannot round-trip that case unambiguously. Keep Nullable(Tuple) as a single quoted CSV field on both output and input, regardless of input_format_csv_deserialize_separate_columns_into_tuple, and document the limitation in the setting description. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Done in 65f1c79. Dropped the legacy separate-columns input fallback: Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260714-173500 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 42/48 (87.50%) · Uncovered code |
CI finish ledger — 65f1c79CI fully finished on this HEAD (Finish Workflow + Mergeable Check pass; only CH Inc sync pending, which is exempt). CIDB shows ZERO FAIL/ERROR test rows at this commit.
Session id: cron:our-pr-ci-monitor:20260714-233000 |
A bare Tuple with a leading Nullable element serialized into separate CSV columns (e.g. `\N,1` for `Tuple(Nullable(Int32), Int32)`) was mistaken for the whole Tuple being NULL when input_format_null_as_default = 1 (the default): the row was replaced by a default and the trailing element broke parsing with INCORRECT_DATA. Issue ClickHouse#106247. A leading `\N` in a separate-column Tuple is ambiguous: it can be the first element's NULL, or the whole column being NULL followed by the next top-level column. Disambiguate by the remaining field budget: the element-wise parse consumes the Tuple's recursive CSV cell width, and the columns after it need at least their own widths, so element-wise is only chosen when enough fields remain on the row; otherwise the `\N` is the whole-column NULL/default. The per-type cell-width rule is shared with the CSV header flattening in getCSVSeparateColumnsWidth; the trailing budget is precomputed once per row. A Nullable(Tuple) is written and read as a single CSV field (ClickHouse#108959), so it never enters this separate-columns path; only bare tuples do, and their widths are statically known. Closes: ClickHouse#106247 Co-Authored-By: Claude Fable 5 <[email protected]>
Backport #108959 to 26.7: Serialize Nullable(Tuple) as a single CSV field
…uple-separate-columns-107342 Serialize Nullable(Tuple) as a single CSV field
Related: #107342
Related: #107371
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Serialize a
Nullable(Tuple(...))column as a single CSV field instead of flattening it into separate columns. Previously a non-null value was written as several CSV fields while aNULLwas a single\N, giving a row-dependent column count that brokeCSVWithNames/CSVWithNamesAndTypesheaders and round-trips.Description
Follow-up to #107371 (closed #107342), reported by @ Avogar.
#107371madeCSVWithNames(AndTypes)flatten Tuple columns in the header to match the data width. But aNullable(Tuple(...))value has a row-dependent width under the defaultoutput_format_csv_serialize_tuple_into_separate_columns = 1:NULLrow writes a single\Nfield.The header was flattened to N columns, matching only the non-null rows, so
NULLrows desynced the column count and the data did not round-trip (CANNOT_PARSE_INPUT):Fix: keep a
Nullable(Tuple)as a single quoted CSV value (it is not flattened), so every row —NULLor not — is exactly one field and the header stays one cell. A bareTuple(not wrapped inNullable) is still flattened as before. Input parsing is made symmetric so the value round-trips.Changes:
SerializationNullable::serializeTextCSV: when the nested serialization is a tuple, write it as a single CSV value (disable separate-columns serialization for the nested tuple).SerializationNullable::deserializeTextCSV/tryDeserializeTextCSV: symmetric, so the single field reads back.FlattenTupleForCSVHeader: no longer unwrapsNullable, so aNullable(Tuple)header stays one cell.CSVFormatReader::readField: removed the now-staleis_nullable_empty_tupleexception (from FixNullable(Tuple)not working withCSV,MsgPackformat properly #100038). With the single-field serialization an empty CSV field is no longer a validNullable(Tuple())value, so under the defaultinput_format_csv_empty_as_default = 1it becomes the nullable default (NULL), like every other Nullable type, instead of throwing while looking for(.04340_csv_with_names_tuple_header: updated theNullable(Tuple)case to the new single-field behavior and added NULL/non-null width-consistency, a nestedNullable(Tuple(Tuple))case, a round-trip-with-NULLs case, and empty-input-field -> NULL cases forNullable(Tuple())/Nullable(Tuple(Int32)).Version info
26.7.5.5