Skip to content

Read empty Nullable(String) as empty string in CSV via input_format_csv_missing_nullable_as_empty_string - #107577

Merged
alexey-milovidov merged 12 commits into
masterfrom
fix_csv_input_empty_as_default_for_string
Jun 30, 2026
Merged

alexey-milovidov merged 12 commits into
masterfrom
fix_csv_input_empty_as_default_for_string

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

When reading CSV with input_format_csv_empty_as_default = 1, a missing (empty, unquoted) value of a Nullable(String) column is read as NULL. In some cases it is more convenient to read it as an empty String instead. This adds a new setting input_format_csv_missing_nullable_as_empty_string (disabled by default) that switches a missing Nullable(String) value to an empty String, regardless of input_format_csv_empty_as_default. The default behavior is unchanged.

The type check is folded into the existing per-empty-field type inspection in CSVFormatReader::readField (the one that already handles the Nullable(Tuple()) exception), so no extra type check is added to the hot path.

This continues and supersedes #58225 by @KevinyhZou (the original fork branch could not be updated). It rebases the change onto current master, wires the setting into the current settings structure, and extends the test to cover both the default (NULL) and the opt-in (empty String) behavior.

Related: #58225

Changelog category (leave one):

  • Improvement

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

Added a setting input_format_csv_missing_nullable_as_empty_string (disabled by default). When enabled, a missing value of Nullable(String) in CSV input is read as an empty String instead of NULL, regardless of input_format_csv_empty_as_default.

Version info

  • Merged into: 26.7.1.290 (included in 26.7 and later)

KevinyhZou and others added 5 commits March 29, 2024 12:59
…_as_default_for_string

# Conflicts:
#	docs/en/interfaces/formats.md
#	docs/en/operations/settings/settings-formats.md
#	src/Core/Settings.h
#	src/Core/SettingsChangesHistory.h
#	src/Formats/FormatFactory.cpp
#	src/Processors/Formats/Impl/CSVRowInputFormat.cpp
The line setting `format_settings.csv.empty_string_is_not_null` from the
PR change was lost while resolving the merge conflict in
`FormatFactory.cpp` (master's version was taken before re-applying the
addition). Re-apply it.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The reviewer was concerned that the original change altered the correct
default behavior, where an empty `Nullable(String)` value in CSV becomes
`NULL`. The new setting `input_format_csv_empty_string_is_not_null` is
opt-in (disabled by default), so the default behavior is preserved.

Make the test demonstrate this explicitly: it now checks both that the
default reads the missing value as `NULL`, and that enabling the setting
reads it as an empty `String`. The test is now self-contained (inline
CSV via `printf`), so the separate `data_csv/csv_empty_for_string_field.csv`
fixture is removed.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…V behavior

Rewrite `02811_csv_input_empty_as_default_for_nullable_string` to be
self-contained (inline CSV via `printf`) and to check both branches:
with `input_format_csv_empty_string_is_not_null = 0` the missing value of
`Nullable(String)` is read as `NULL` (the unchanged default), and with the
setting enabled it is read as an empty `String`. Goes together with the
removal of the `data_csv/csv_empty_for_string_field.csv` fixture in the
previous commit.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2626f8c]

Summary: ✅


AI Review

Summary

This PR adds input_format_csv_missing_nullable_as_empty_string, wires it into CSV format settings, and adds a focused stateless test covering the default NULL behavior plus the opt-in empty-string behavior for both Nullable(String) and LowCardinality(Nullable(String)). I verified the prior bot finding about LowCardinality(Nullable(String)) against the current code and test, and it is addressed. I did not find any unresolved correctness, compatibility, or testing issues.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jun 16, 2026
@Algunenano Algunenano self-assigned this Jun 16, 2026
Comment thread src/Core/FormatFactorySettings.h Resolved
alexey-milovidov and others added 7 commits June 19, 2026 05:58
…owCardinality(Nullable(String))

The setting was only honored for a top-level `Nullable(String)`. For
`LowCardinality(Nullable(String))` the top-level type is not `Nullable`,
so `type->isNullable()` was false, `keep_empty_value` stayed false, and a
missing CSV value was still inserted as the column default (`NULL`),
silently ignoring the setting.

Detect the nullable-string case with `isNullableOrLowCardinalityNullable`
plus `isString(removeLowCardinalityAndNullable(type))`, so both
`Nullable(String)` and `LowCardinality(Nullable(String))` fall through to
normal deserialization and produce an empty `String`. The `Nullable(Tuple())`
exception is unaffected (it is checked separately and is never low-cardinality).

Extend the test to cover a `LowCardinality(Nullable(String))` column in
both the default (`NULL`) and the opt-in (empty `String`) behavior.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…istory block

While this PR was open, `master` advanced its development version from `26.6`
to `26.7` (a new `addSettingsChanges(..., "26.7", ...)` block was added). A new
setting introduced now first ships in `26.7`, so its `SettingsChangesHistory`
entry must live in the `26.7` block, not `26.6`. Move it accordingly.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Address review by @Algunenano: the previous name
`input_format_csv_empty_string_is_not_null` was hard to read. Rename it
to `input_format_csv_missing_nullable_as_empty_string`, which states the
behavior directly: a missing `Nullable(String)` value in CSV is read as
an empty `String` instead of NULL.

The setting is new and not yet released (it lives in the `26.7` block of
`SettingsChangesHistory`), so this is a plain rename rather than an alias.
The internal `FormatSettings::CSV` field is renamed to
`missing_nullable_as_empty_string` to match, and the embedded format-settings
documentation table and the test
`02811_csv_input_empty_as_default_for_nullable_string` are updated
accordingly. Behavior is unchanged.
@alexey-milovidov alexey-milovidov changed the title Read empty Nullable(String) as empty string in CSV via input_format_csv_empty_string_is_not_null Read empty Nullable(String) as empty string in CSV via input_format_csv_missing_nullable_as_empty_string Jun 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.40% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 77.60% 77.60% +0.00%

Changed lines: Changed C/C++ lines covered: 37/37 (100.00%) · Uncovered code

Full report · Diff report

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Status (continue-pr triage, HEAD 2626f8c0):

  • CI: fully green — 170 checks, 149 passed / 0 failed / 21 skipped. The earlier arm_tsan Stress flakes (refresh-scheduling logical error STID 2508-3e7b = Logical error: 'Unexpected exception in refresh scheduling' (STID: 2508-3e7b) #106737, plus a stress-startup "Cannot start clickhouse-server" flake) cleared on re-run and are unrelated to CSV parsing.
  • AI Review: ✅ Approve; LLVM coverage of changed lines 37/37 (100%).
  • Human review: ✅ Approved by @Algunenano — his sole ask (rename to input_format_csv_missing_nullable_as_empty_string) is implemented and the thread is resolved. 0 unresolved review threads.
  • mergeable=MERGEABLE; no conflicts. Merge-base is ~1 day old (2026-06-29 10:05) and CI is green, so no master-merge was warranted.

No code changes needed this pass. The PR is fully ready; the only remaining step is the maintainer merge.

@alexey-milovidov
alexey-milovidov merged commit 54ce3dc into master Jun 30, 2026
173 of 174 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix_csv_input_empty_as_default_for_string branch June 30, 2026 18:48
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 30, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…pty_as_default_for_string

Read empty Nullable(String) as empty string in CSV via input_format_csv_missing_nullable_as_empty_string
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