bug: CSV/TSV `COPY INTO <table>` stores the NULL marker (`\N`, or the `NULL_DISPLAY` text) as a string in a `STRING NOT NULL` column instead of rejecting the row
Maintainers usually reply within 1 day
@youngsofun is already working on this.
Since Oct 23, 2026.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
Research direction
Start with src/query/formats/src/field_decoder/separated_text.rs, especially SeparatedTextDecoder::read_field and read_nullable, to trace how null_if is checked for nullable and non-nullable columns. Add or locate focused CSV and TSV load tests for STRING NOT NULL with the default \N marker and a custom NULL_DISPLAY; done means those rows are rejected while valid string rows still load.
Written by the indexing model from the issue text.
Description
Search before asking
- I had searched in the issues and found no similar issues.
Version
main e9b49fd (source build, v1.2.953-nightly-e9b49fde); also v1.2.952-nightly-8862a6285b.
What's Wrong?
When a CSV or TSV file holds a NULL (written by Databend's own unload as \N, or as the configured NULL_DISPLAY) and
the target column is STRING NOT NULL, the load succeeds and stores the two-character text \N (or NULL). The
result reports 0 errors. The NOT NULL constraint the user declared is bypassed, and a value that was never in the source
appears in the table.
Every other NOT NULL type rejects the same field (e.g. INT: Invalid value '\N' for column 2 (n Int32): invalid text for number), and so do NDJSON loads and INSERT … VALUES (1, NULL). Even an empty CSV field for the same
STRING NOT NULL column is rejected (EMPTY_FIELD_AS=NULL). Only the explicit NULL marker gets through. A column
DEFAULT does not change this.
Cause: SeparatedTextDecoder::read_field (src/query/formats/src/field_decoder/separated_text.rs:96) checks the field
against null_if (built from NULL_DISPLAY) only in read_nullable (line 170), i.e. only for nullable columns. For a
non-nullable column it goes straight to the type's parser. Every parser except STRING fails on \N, but
ColumnBuilder::String (line 113) accepts it as data. The NULL check (with an error like "null value is not allowed for
non-nullable field", as the NDJSON reader gives) should come before the per-type dispatch for unquoted fields.
Related but different: #20611 (TSV reads the escaped literal \\N as NULL in a nullable column).
How to Reproduce?
CREATE OR REPLACE STAGE s116;
CREATE OR REPLACE TABLE src (id INT, name STRING NULL, n INT NULL);
INSERT INTO src VALUES (1, NULL, 1), (2, 'bob', 2);
COPY INTO @s116/csv/ FROM src FILE_FORMAT = (TYPE = CSV); -- file: 1,\N,1 / 2,"bob",2
COPY INTO @s116/tsv/ FROM src FILE_FORMAT = (TYPE = TSV);
COPY INTO @s116/csvn/ FROM src FILE_FORMAT = (TYPE = CSV NULL_DISPLAY = 'NULL');
CREATE OR REPLACE TABLE dst (id INT, name STRING NOT NULL, n INT NULL);
COPY INTO dst FROM @s116/csv/ FILE_FORMAT = (TYPE = CSV); -- 2 rows loaded, 0 errors
COPY INTO dst FROM @s116/tsv/ FILE_FORMAT = (TYPE = TSV); -- 2 rows loaded, 0 errors
COPY INTO dst FROM @s116/csvn/ FILE_FORMAT = (TYPE = CSV NULL_DISPLAY = 'NULL'); -- 2 rows loaded, 0 errors
SELECT id, name, length(name) FROM dst ORDER BY id, name;
-- 1 | NULL | 4 <-- the string 'NULL'
-- 1 | \N | 2 <-- the string '\N'
-- 1 | \N | 2
-- 2 | bob | 3 (×3)
For comparison, the same NULL into an INT NOT NULL column:
CREATE OR REPLACE TABLE dst_int (id INT, name STRING NULL, n INT NOT NULL);
INSERT INTO src VALUES (3, 'carl', NULL);
COPY INTO @s116/csv2/ FROM src FILE_FORMAT = (TYPE = CSV);
COPY INTO dst_int FROM @s116/csv2/ FILE_FORMAT = (TYPE = CSV);
-- error: Invalid value '\N' for column 2 (n Int32): invalid text for number
Expected: the row with the NULL marker is rejected for the STRING NOT NULL column (an error, or a counted error under
ON_ERROR = CONTINUE), as for every other type.
Single node, default settings, HTTP handler.
Are you willing to submit PR?
- Yes I am willing to submit a PR!
- Dominant language
- Rust
- Stars
- 9.5k
- Forks
- 903
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 204
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from databendlabs/databend
-
bug: segment pruning skips rows when only some blocks have statistics of an added columnPossibly taken @zhyass claimed this today. OpenC-bug
databendlabs/databend#21244 · 1 assignee ·
Maintainers usually reply within 1 day
-
bug: ORDER BY ... NULLS LAST LIMIT returns wrong rows when an inverted index answers the filter and the sort column has NULLsPossibly taken @b41sh claimed this today. OpenC-bug
databendlabs/databend#21243 · 1 assignee ·
Maintainers usually reply within 1 day
-
Feature: Reduce role-graph work for explicit secondary rolesPossibly taken @TCeason claimed this 1 day ago. OpenC-feature
databendlabs/databend#21226 · 1 assignee ·
Maintainers usually reply within 1 day
-
Feature: Key role-dependent query results by authorization contextPossibly taken @TCeason claimed this 1 day ago. OpenC-feature
databendlabs/databend#21225 · 1 assignee ·
Maintainers usually reply within 1 day
-
bug: filters folded to false on block statistics drop matching rows: cast-eliminated equality under NOT, float arithmetic over NaN and infinities, variant IS DISTINCT FROMPossibly taken @forsaken628 claimed this 1 day ago. OpenC-bug
databendlabs/databend#21216 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in databendlabs/databend
Similar issues
-
marketing
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
eliasstravik/herdr-projects#1605 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
jlcodes99/cockpit-tools#3332 ·
Maintainers usually reply within 3 days
-
Cognito: the email MFA code (EMAIL_OTP challenge after a password flow) has 8 digits; AWS delivers 6Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
aws/aws-emulator#692 ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 82/100
pamburus/hl#1779 · 1 comment ·
Maintainers usually reply within 1 day