Repository navigation
Description
Actual Behavior
A parallel CSV LOAD with the user-requested non-strict option (STRICT 'false') can split a file in the middle of an enclosed field that spans multiple physical lines. The first byte range is given directly to the production CsvReader; that range returns:
invalid input: csvParser error: unterminated quoted field
This was reproduced through matrixone's actual ExternalParam / readFile / NewCsvReader path using an in-memory ETL filesystem. The quoted field is normal RFC-style CSV ("value <newline> more value") and parses successfully when the whole file is read as one range.
Expected Behavior
A parallel CSV LOAD must not split inside a quoted field. It should keep every range parseable, even under non-strict (STRICT 'false') operation. The exact data should produce one complete row in the first range.
Environment
- Commit ID:
b24d1b311555e0b6f3d56eb37f9a2e9617e9a5b7 - OS: macOS (Darwin, arm64)
- Go version:
go1.27.1 darwin/arm64 - Standalone
mo-servicebuilt withmake build; the reproduction directly exercises the same CSV reader and ETL file range used by standalonemo-service.
Steps to Reproduce (Minimal)
I added minimal reproduction tests to pkg/sql/colexec/external/loom_test.go. The core case writes this file:
1,"aaaaaaaaa
b"
2,x
With two parallel readers, ReadFileOffset picks the initial boundary at byte offset 10, which is inside the quoted field before its internal newline. Because getTailSizeNoStrict only advances to the next physical newline, it errors by placing the end of the first range at byte offset 13:
offsets := []int64{0, 13, 13, -1}The current readFile call then gives the real CsvReader only bytes [0,13). The first range is:
1,"aaaaaaaaa
and contains neither the closing quote nor the end of record 1. ReadBatch therefore fails.
The reproduction is:
go test ./pkg/sql/colexec/external \
-run '^TestLoomParallelCSVReaderKeepsNonStrictQuotedMultilineSplitParseable$' \
-count=3Additional information
- Root cause location:
pkg/sql/colexec/external/external.goaroundgetTailSizeNoStrict. ReadFileOffsetpasses the guessed parallel boundary togetTailSizeNoStrict.getTailSizeNoStrictusesbufio.Reader.ReadString('\n')and ignoresFIELDS ENCLOSED BY. For a quoted spanning record, this makes that embedded newline look like a safe split boundary even though the quote is still open.- The strict scanner tries to validate the tail; the independent non-strict branch instead advances to the first newline without any quote state.
- A small operator-level test already shows the direct production reader rejected the first range; the failure was reproduced 3 out of 3 runs.
- The direct test also pins the bad offsets (
0..13and13..-1) and proves the first sub-range is not parseable as CSV.
Found by Loom bug hunt (module: custom-a9872c7d6e; tests: unit, white-box, end-to-end)
Activity
fix(csv): preserve multiline records in parallel non-strict LOAD (#30399
XuPeng-SH commentedon Oct 17, 2026
增量实测验证(2026-10-17):main
a322466757b9b0165c59fbda565608653d923b2a,Linux/amd64、Go 1.27.1、匹配 CGo 产物。完整运行
pkg/sql/util/csvparser、pkg/common/runtime、pkg/sql/colexec/external的普通和-race -count=1测试,均通过。external 每次仅跳过一个尚缺 MinIO 依赖的 Arrow 对象存储测试;该跳过项不是本 CSV issue 的通过证据。另外独立执行真实 MySQL 协议 SQL:272,192,894 字节的引号 CSV,17,000 条记录,每条包含字段内换行;目标表没有唯一约束。串行、严格并行、非严格并行(空/default sql_mode)四种路径均得到 rows=17000、distinct(id)=17000、payload_bytes=272000000、bad_tails=0、sum(id)=144508500。并行路径实际观察到两个区间;非严格分界为 136108404。观察 hook 的阈值保持生产默认 128 MiB,仅把单 CN fixture 的 worker budget 明确为 2。仓库内 58 字节 public-SQL 回归也实际执行,区间 [0,39)、[39,EOF),完整字段/转义/行身份断言通过。
本 issue 覆盖的修复已验证,按约定转给 @Ariznawlll。
Ariznawlll commentedon Oct 17, 2026
测试版本
main7c2847207dc5bd87f6c23dc7318f7be21c0a5f2a(fix(csv): preserve multiline records in parallel non-strict LOAD #30399 已合入)原问题验证
独立生成 272,141,894 字节 CSV,17,000 条记录,每条 16,000 字节 payload 含引号内换行;目标表没有唯一键,因而行数/去重断言能发现重复或丢失。以
PARALLEL 'TRUE' STRICT 'FALSE'真实 SQL 加载 3/3 成功。每轮精确得到COUNT(*)=17000、COUNT(DISTINCT id)=17000、SUM(id)=144508500、SUM(CHAR_LENGTH(payload))=272000000、错误尾字节数0。生产 128 MiB/reader 阈值未下调。实际编译日志每轮记录len of cnList is 2, mcpu is 2, file size is 272141894;按当前GetExternParallelSize规则实际选择两个 byte-range reader。原问题的引号内换行没有被当作安全分界。Happy Path 覆盖
STRICT 'TRUE'下也 3/3 精确得到上述全部计数与值。Unhappy Path 覆盖
-race -count=3下通过;畸形 CSV 的失败没有被录成成功 golden。白盒验证
TestParallelNonStrictKeepsQuotedMultilineSplitParseable、TestParallelNonStrictCsvReaderRanges、TestParallelNonStrictUnbalancedQuoteFallback等直接调用生产ReadFileOffset/CsvReader的测试以-race -count=3PASS。2 CN SQL 运行的编译日志证实选择 2 个 CN、2 个 worker;普通单 CN 测试未用于推断分片。回归测试
MOTR 大数据场景
suites/scenarios/14_issue_regression/issue_30378_parallel_csv_bigdata.py与配对out/issue_30378_parallel_csv_bigdata.out已追加当日汇总 PR #247,head015dcb39。仅在明确配置可被所有 CN 读取的MO_CSV_PARALLEL_SHARED_DIR时运行,否则明确 SKIP、不得算成功;在上述 2 CN 配置定向 3/3、0 failed、0 skipped,同时每轮非严格/严格两次原规模加载与错误路径均通过。完整 suite 和共享集成 CI 未完成;PR 尚未合入。测试证据
/private/tmp/mo-30265-qa-adWo0K/qa_multi_cn.log有 2 CN / 2 worker 编译记录;脚本/private/tmp/mo-30265-qa-adWo0K/qa_30378_csv_scale.py对全部值进行独立精确断言。var/log/run-1792256609936742000:total=3 success=3 failed=0 skipped=0。每轮测试结束已清理临时表与 272 MB 输入;共享集群未执行全局清理。测试结论
测试通过。