Skip to content

Fix empty CSV/TSV fields storing 0 in an Enum without a 0 element - #130975

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
lazerg:fix/issue-130598-empty-field-enum-default
Nov 13, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
lazerg:fix/issue-130598-empty-field-enum-default

Conversation

@lazerg

@lazerg lazerg commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #130598

When CSV or TSV reads an empty field as the default value, it called column.insertDefault(), which writes a raw 0 into the column. For an Enum without a 0 element that value is out of domain: the INSERT works, but reading the column later throws UNKNOWN_ELEMENT_OF_ENUM. The same happened for a bad value with input_format_csv_use_default_on_bad_values and for fields cut off with allow_variable_number_of_columns. These places now call type->insertDefaultInto(column), so an Enum gets its first element, as JSONEachRow, TSKV and Values already do.

05621_csv_tsv_empty_field_enum_default covers the four paths and an INSERT ... FORMAT CSV into a MergeTree table. Without the fix it fails with UNKNOWN_ELEMENT_OF_ENUM.

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):

Fixed an empty or missing CSV/TSV field being stored as 0 in an Enum column that has no 0 element, which made later reads fail with UNKNOWN_ELEMENT_OF_ENUM. Now the field gets the first Enum element.


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

Version info

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

@clickhouse-gh clickhouse-gh Bot added the comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). label Nov 12, 2026
@PedroTadim PedroTadim self-assigned this Nov 12, 2026
@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Nov 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [307520b]

Summary: ✅


AI Review

Summary

The PR uses type-aware defaults for empty, invalid, and omitted CSV/TSV fields, preventing out-of-domain values in Enum columns. The previously reported header-omission issue is fixed in 307520bba0fb84d956382da0a9a38e469d36b62f, including the shared RowBinary and MySQLDump callers, and its review thread has been resolved. No remaining findings. The focused regression test passed in Fast test at the reviewed head; broader CI is still running.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 307520bba with master 4a760bb3a (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.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.59, programs/clickhouse-keeper ×0.75 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 6.3 s 10.5 s +6.8 s (+183%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.5 s 7.2 s +5.1 s (+253%)
Compile time of recompiled translation units

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

Job report

@PedroTadim
PedroTadim added this pull request to the merge queue Nov 13, 2026
Merged via the queue into ClickHouse:master with commit c2ee5c2 Nov 13, 2026
205 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 13, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

@lazerg @PedroTadim — ClickGap found the following in this PR:

Close anything that's wrong or already addressed.

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-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 CSV/TSV field stores out-of-domain Enum value 0 with empty_as_default

4 participants