Repository navigation
Read empty Nullable(String) as empty string in CSV via input_format_csv_missing_nullable_as_empty_string - #107577
Conversation
…_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]>
|
Workflow [PR], commit [2626f8c] Summary: ✅
AI ReviewSummaryThis PR adds Final VerdictStatus: ✅ Approve |
…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]>
…_as_default_for_string
…_as_default_for_string
…_as_default_for_string
…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]>
…_as_default_for_string
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.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 37/37 (100.00%) · Uncovered code |
|
Status (continue-pr triage, HEAD
No code changes needed this pass. The PR is fully ready; the only remaining step is the maintainer merge. |
…pty_as_default_for_string Read empty Nullable(String) as empty string in CSV via input_format_csv_missing_nullable_as_empty_string
When reading CSV with
input_format_csv_empty_as_default = 1, a missing (empty, unquoted) value of aNullable(String)column is read asNULL. In some cases it is more convenient to read it as an emptyStringinstead. This adds a new settinginput_format_csv_missing_nullable_as_empty_string(disabled by default) that switches a missingNullable(String)value to an emptyString, regardless ofinput_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 theNullable(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 (emptyString) behavior.Related: #58225
Changelog category (leave one):
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 ofNullable(String)in CSV input is read as an emptyStringinstead ofNULL, regardless ofinput_format_csv_empty_as_default.Version info
26.7.1.290(included in26.7and later)