Repository navigation
Fix reading a trailing field delimiter at the end of TSV and CSV input - #128436
alexey-milovidov merged 5 commits into
Conversation
When input ended with a field delimiter and no final newline, the empty field after it was deserialized at EOF. Some types (integers, Decimal, Nullable of them) throw ATTEMPT_TO_READ_AFTER_EOF there, while the same empty field before a line end is parsed. This made the whole query fail, e.g. for truncated files with input_format_*_allow_variable_number_of_columns. Read such a field as if a line end followed it, so input without a final newline is parsed exactly like the same input with one. Closes ClickHouse#91776
alexey-milovidov
left a comment
There was a problem hiding this comment.
This isn't elegant. Do I understand correctly, that the empty string field isn't parsed correctly if the file ends with it with no extra newline, and it is somehow interacts with the "variable number of columns" mode? Let's think further...
With `input_format_tsv_empty_as_default` / `input_format_csv_empty_as_default` the readers treated a field as empty only if it was followed by the field delimiter, or, for the last file column, by the end of the row. With a variable number of columns a row can end before the last file column, so an empty field there was passed to the type's parser: `Float64` and `Date` failed even with a final newline, `Nullable(Int64)` became `0` instead of `NULL`, and integers failed with `ATTEMPT_TO_READ_AFTER_EOF` when the input had no final newline. A field is now empty if it is followed by the field delimiter or the end of the row, regardless of its position. This replaces the previous workaround that read the field from a one-byte `"\n"` buffer at EOF. ClickHouse#91776 ClickHouse#128436 (review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [dd91426] Summary: ✅
AI ReviewSummaryThe PR fixes empty trailing fields in short Final Verdict✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 13 s compile time in total, 8 of them have a recent master baseline. |
#128436 changed `CSVFormatReader::readField` to treat a field starting with `\r` as empty with `input_format_csv_empty_as_default`, so the fuzzer file `clusterfuzz-testcase-minimized-arrow-csv-fuzz-5085419734892544` now fails with `CANNOT_PARSE_INPUT_ASSERTION_FAILED` instead of being read as one row. This was the reason the merge queue rejected the PR: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=gh-readonly-queue/master/pr-125134-e347281f9c9d421459e72eefc44846ec85d67c06&sha=35025568ed58256edb98198b0a30fd72fa93fb7d&name_0=MergeQueueCI Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #91776
With
input_format_tsv_allow_variable_number_of_columns/input_format_csv_allow_variable_number_of_columnsandinput_format_tsv_empty_as_default/input_format_csv_empty_as_defaultenabled, a row that ends with a field delimiter (with or without a final newline) failed withATTEMPT_TO_READ_AFTER_EOFor a parse error, because the empty field before the end of the row was only treated as default when it belonged to the last column of the schema.Now, when the empty-as-default setting is enabled, an empty field followed by the field delimiter, a line end, or EOF receives its default value, regardless of its position in the schema. The change applies to
TSV,CSV, their header variants,TSVRaw, andHiveTextthrough their shared readers (TabSeparatedFormatReader::readFieldandCSVFormatReader::readField).Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix parsing empty trailing fields in
TSVandCSVinput with a variable number of columns andinput_format_tsv_empty_as_defaultorinput_format_csv_empty_as_defaultenabled, including truncated rows without a final newline.Workflow [PR]
Sync PR [sync-upstream/pr/128436]
Version info
26.11.1.1151-master(included in26.11and later)