Skip to content

Fix input empty as default for nullable string field in CSV InputFormat - #58225

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
KevinyhZou:fix_csv_input_empty_as_default_for_string
Jun 30, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
KevinyhZou:fix_csv_input_empty_as_default_for_string

Conversation

@KevinyhZou

@KevinyhZou KevinyhZou commented Dec 26, 2023 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Improvement

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

While deserialize csv input, if we set the config input_format_csv_empty_as_default = true, which would set default value to field if the input is empty, and this is also take effect for Nullable(String) type, in this case, if the input is a empty string, then the field will be set default value as NULL, as show below
image

Here it is not suitable,to set NULL when the input is empty for Nullable(String) type, and it is better to set a empty string for the field.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

@KevinyhZou KevinyhZou changed the title Fix input empty for nullable string field in CSV InputFormat Fix input empty as default for nullable string field in CSV InputFormat Dec 26, 2023
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Dec 26, 2023
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-bugfix Pull request with bugfix, not backported by default label Dec 26, 2023
@robot-ch-test-poll4

robot-ch-test-poll4 commented Dec 26, 2023 •

Copy link
Copy Markdown
Contributor

This is an automated comment for commit 7ee8e14 with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Check nameDescriptionStatus
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR⏳ pending
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests❌ failure
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc❌ failure
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts❌ failure
Successful checks
Check nameDescriptionStatus
A SyncThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integrational tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ success
Mergeable CheckChecks if all other necessary checks are successful✅ success
PR CheckThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand. So, here "empty as default" for Nullable(String) should yield NULL.

It looks like, you've changed the correct behavior with the incorrect one.

@alexey-milovidov alexey-milovidov self-assigned this Dec 26, 2023
@alexey-milovidov
alexey-milovidov marked this pull request as draft December 26, 2023 14:23
@alexey-milovidov

Copy link
Copy Markdown
Member

Ok, I understand that this is just another choice.

Then it should be controlled by a setting, and the category has to be changed from "bug fix" to something else.

@KevinyhZou

KevinyhZou commented Dec 27, 2023 •

Copy link
Copy Markdown
Contributor Author

I have add a csv settings default_empty_for_nullable_string to controll whether to set default value NULL or empty to Nullable(String) type field, the default value is false. please reivew this, thanks. @alexey-milovidov

@KevinyhZou
KevinyhZou marked this pull request as ready for review December 27, 2023 11:33
@robot-ch-test-poll robot-ch-test-poll added pr-improvement Pull request with some product improvements and removed pr-bugfix Pull request with bugfix, not backported by default labels Dec 28, 2023
@KevinyhZou
KevinyhZou force-pushed the fix_csv_input_empty_as_default_for_string branch 2 times, most recently from 10d790f to c4e8eb6 Compare December 29, 2023 09:23
@KevinyhZou

Copy link
Copy Markdown
Contributor Author

cc @alexey-milovidov

@KevinyhZou

Copy link
Copy Markdown
Contributor Author

cc @alexey-milovidov

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is slow.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong punctuation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setting name is difficult to understand.

Comment thread src/Core/Settings.h Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation is not enough to understand the setting.

@alexey-milovidov

Copy link
Copy Markdown
Member

I can continue this PR, but it will take more time.

@alexey-milovidov
alexey-milovidov marked this pull request as draft February 21, 2024 07:39
@alexey-milovidov

Copy link
Copy Markdown
Member

@KevinyhZou,

The setting should be named input_format_csv_empty_string_is_not_null

The documentation should say:

Controls how `Nullable(String)` is read from a missing value in CSV. A missing value is an empty space between/before/after commas, not surrounded by quotes. If this setting is enabled, regardless of the value of `input_format_csv_empty_as_default`, the missing value of `Nullable(String)` will be interpreted as an empty `String`, not as NULL.

The setting should not be enabled by default.

The code should not do type checks in the readField - it should be outside of the loop.

^ if these requirements are fulfilled, we can merge this PR.

@KevinyhZou

KevinyhZou commented Feb 22, 2024 •

Copy link
Copy Markdown
Contributor Author

Thanks for you review. @alexey-milovidov But, The check code may should not be outside of the for loop, as we should check the field type whether is Nullable(String), if outside, this check should not easy to do. So I put the check as a sub-check into the empty_as_default check codes, it should minimize the impact on performance as little as possible, as the code shows. would this be ok ?

@KevinyhZou
KevinyhZou force-pushed the fix_csv_input_empty_as_default_for_string branch from 6a9d0aa to e4574fb Compare February 22, 2024 05:12
@KevinyhZou
KevinyhZou marked this pull request as ready for review March 8, 2024 07:17
@KevinyhZou
KevinyhZou force-pushed the fix_csv_input_empty_as_default_for_string branch from e4574fb to 6044616 Compare March 29, 2024 01:56
@KevinyhZou
KevinyhZou force-pushed the fix_csv_input_empty_as_default_for_string branch from 6044616 to ddfca6b Compare March 29, 2024 02:27
@KevinyhZou
KevinyhZou force-pushed the fix_csv_input_empty_as_default_for_string branch from cecfd2c to 7ee8e14 Compare March 29, 2024 05:00
@KevinyhZou

Copy link
Copy Markdown
Contributor Author

cc @alexey-milovidov

@clickhouse-gh

clickhouse-gh Bot commented Jun 25, 2024

Copy link
Copy Markdown
Contributor

Dear @alexey-milovidov, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@alexey-milovidov

Copy link
Copy Markdown
Member

I've continued this change in #107577: rebased onto current master, wired the new setting input_format_csv_empty_string_is_not_null into the current settings structure, kept it disabled by default, moved the type check into the existing per-empty-field inspection in readField, and extended the test to cover both the default (NULL) and the opt-in (empty String) behavior. Thanks @KevinyhZou — your original commit is preserved in that branch. I could not push to your fork directly (maintainer edits were denied by GitHub), hence the new PR.

@alexey-milovidov
alexey-milovidov merged commit 6995ed2 into ClickHouse:master Jun 30, 2026
@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
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 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.

5 participants