Skip to content

[Bug]: CSV scans drop whitespace-only single-column records #30252

Closed

Description

@iamlinjunhong

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-service built 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=1

Equivalent SQL reproduction:

  1. Create whitespace.csv with exactly one space on the first line and x on the second line.
  2. 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

  1. added
    kind/bug
    on Oct 15, 2026
  2. added 2 commits that reference this issue on Oct 15, 2026
    187e9dc
    ecdec54
  3. added
    ai-easy
    on Oct 20, 2026
  4. Ariznawlll commented on Oct 20, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:官方 main
    • commit:7c146f4adbf068dd0c06b377157cfb7d7698b1eb
    • 修复:matrixone PR fix: preserve external CSV integer values and whitespace records #30262,merge commit 3d78d8403d1ad3dfe55926ad620e417feee7afe0,已确认进入上述 main。
    • 部署方式:隔离构建的 macOS arm64 1 CN / 1 TN / 1 LogService,MySQL 协议端口 46001,独立数据目录。
    • 测试日期:2026-10-20(北京时间)。

    原问题验证

    使用两行 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 覆盖

    1. 普通 x 行保留,行号为 2;三轮一致。
    2. 每轮测试库均删除,未复用线上数据。

    Unhappy Path 覆盖

    1. JSONLINE 对照文件含空白行。三轮外部扫描只得到 (1,'alpha',1)、(2,'beta',3),确认未改变 JSONLINE 的跳空白策略。
    2. 同轮数值外部表的越界记录 127.5 返回 NULL 与错误元数据,未被错误当成可用数据。

    白盒验证

    TestWhitespaceOnlyRecord、TestScanRecordMatchesReadFraming、TestWhitespaceRecordCancellation 运行 -count=3 通过;未运行 -race。

    回归测试

    测试证据

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions