Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
17a6200f59e764729e5544908fffd5480ae88279
Other Environment Information
- Hardware parameters: arm64, 10 CPUs
- OS type: Darwin (macOS)
- Others: standalone
mo-servicebuilt from the above commit and started on MySQL port 26201
Actual Behavior
For a one-column CSV external table, this file:
<SPACE>
x
returns only one row, x. The whitespace-only record is silently skipped:
count(*) | group_concat(concat('[', v, ']') order by v)
1 | [x]
The package-level parser reproduction also reads x as its first record instead of " ".
Expected Behavior
An unquoted field consisting of a space is CSV field data, not a blank line. The scan should return two records whose values are " " and "x"; if whitespace-only records are intentionally invalid, the query should report an error rather than silently omit a physical row.
Steps to Reproduce
Deterministic package reproduction:
go test ./pkg/sql/util/csvparser -run '^TestLoomCSVParserPreservesWhitespaceOnlyRecord$' -count=1Equivalent SQL reproduction:
- Create
whitespace.csvwith exactly one space on the first line andxon the second line. - Execute:
CREATE EXTERNAL TABLE whitespace_csv(v varchar(8))
INFILE{'filepath'='stage://probe_stage/whitespace.csv','format'='csv'}
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
SELECT count(*), group_concat(concat('[', v, ']') order by v) FROM whitespace_csv;Additional information
CSVParser.readRecord tracks a whitespaceLine. At end-of-record it executes:
if err == nil && whitespaceLine && len(bytes.TrimSpace(parser.recordBuffer)) == 0 {
parser.recordBuffer = parser.recordBuffer[:0]
parser.recordStartLine = parser.lineNo
continue
}This treats a record whose only field contains spaces/tabs as if it were an empty line. The check uses bytes.TrimSpace after the field has already been accumulated, so a valid unquoted string value is discarded. Quoting the field preserves it, but standard CSV unquoted field bytes and an explicitly configured field terminator determine records; whitespace before the terminator is data for a VARCHAR external column.
Issue searches for CSV whitespace line external table, CSV blank line external table, csvparser whitespace line, and the source comment found no matching report. #24320 was reviewed and is an unrelated Hive external-table feature request.
Found by Loom bug hunt (module: custom-f8abd941a5; tests: unit, white-box, end-to-end)
Activity
fix(csvparser): retain unquoted whitespace-only CSV records
ci: verify matrixorigin#30252 on fresh upstream main and real consumer
Ariznawlll commentedon Oct 20, 2026
测试版本
main7c146f4adbf068dd0c06b377157cfb7d7698b1eb3d78d8403d1ad3dfe55926ad620e417feee7afe0,已确认进入上述 main。原问题验证
使用两行 CSV:第一行仅一个 ASCII 空格,第二行
x。一列 VARCHAR 外部表三轮均得到(__mo_file_line, HEX(v), v IS NULL) = (1,20,0), (2,78,0),COUNT(*)=2、COUNT(v)=2;原先被跳过的空格行现作为真实非 NULL 数据保留。Happy Path 覆盖
x行保留,行号为 2;三轮一致。Unhappy Path 覆盖
(1,'alpha',1)、(2,'beta',3),确认未改变 JSONLINE 的跳空白策略。127.5返回 NULL 与错误元数据,未被错误当成可用数据。白盒验证
TestWhitespaceOnlyRecord、TestScanRecordMatchesReadFraming、TestWhitespaceRecordCancellation运行-count=3通过;未运行-race。回归测试
issue_30250_30252_external_csv_values.test、配对结果与原始空格 CSV 资源;本 issue 的行数、行号、十六进制值、NULL 断言 3/3 通过(每次 13 条语句,文件同时覆盖 [Bug]: CSV external tables truncate unquoted decimals in integer columns #30250)。test/distributed/cases/load_data/external_csv_values.sql包含空行、引号、NULL 与 EOF 边界;本轮未运行完整 BVT/MOTR suite,select without from clause is not supported #247 集成 CI 待确认。测试证据
3 success / 0 failed。HEX(v)=20,行 2HEX(v)=78,总行数 2。测试结论
测试通过。