Skip to content

fix(csv): preserve multiline records in parallel non-strict LOAD - #30399

Merged
mergify[bot] merged 6 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/7e1ad72b85b7fb288bfef5088fb2a95dc7e1fdf2e0d61ba24a0c4938e078cc6c
Oct 17, 2026
Merged

mergify[bot] merged 6 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/7e1ad72b85b7fb288bfef5088fb2a95dc7e1fdf2e0d61ba24a0c4938e078cc6c

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

What this PR does / why we need it:

Parallel non-strict CSV LOAD can split a valid quoted multiline field at a physical newline, causing reader errors or incorrect records. Choose split points by replaying the production CSV parser from the preceding confirmed record boundary. The new ScanRecord operation shares framing and header handling with Read while skipping the field decoding and unescaping that partition planning discards.

Keep best-effort legacy splitting after a CSV syntax failure. Propagate configuration, storage, cancellation and resource-limit errors; close scan readers before fallback; preserve EOF and close-error handling. Retain the configured, overlap-aware physical terminator fallback and bounded worker assignment from main.

The SQL regression uses the existing one-CN integration fixture and a service/path-scoped testing threshold, with a private local worker budget capped by CPUs and query max_dop. This allows a 58-byte input to exercise real parallel admission and execution without a large fixture. Production thresholds are unchanged. Both LOAD planning entrypoints use the shared admission helper, and observer callbacks receive copied offsets.

Validation before the CI follow-up (mo-cgo-test, Go 1.27.1, Darwin/arm64):

  • Full short owning-package tests passed for csvparser, runtime, external, plan and compile, excluding the then-baseline-proven unrelated Arrow fixture. Parser framing/Read interoperation, multiline/custom delimiters, syntax fallback, cancellation/error cleanup and worker assignment regressions passed; full csvparser/runtime race tests also passed.
  • TestLoadCSVParallelNonStrictMultiline passed through the MySQL frontend normally and under race. It observes two actual ranges [0,39) and [39,EOF) with nominal split 29 inside the quoted field, checks complete multiline/escaped values and exactly IDs 1, 2, 3 without a uniqueness constraint, and checks serial execution. Mutating the observer's private offset copy does not affect execution.
  • The same SQL regression fails with only the splitter replaced by exact official-base external.go: ranges become [0,36) and [36,EOF), and LOAD reports mismatched input columns. This is a read-only source overlay retaining the test control.
  • Incremental golangci-lint across all six changed packages reported 0 issues; vet, gofmt and diff checks passed.

CI follow-up and error propagation:

  • Reproduced the Ubuntu/x86 ordinary and coverage UT failure in TestReadFileOffsetClosesTailScanReaders/partial_read_error. The first CSV replay probe now reports the injected storage error immediately; the old test expected three probes from physical-line guessing. Correct the expected reader count to one, retaining the positive-byte-plus-error injection, exact error identity, nil offsets and close-once checks. Retain the remote follow-up's separate JSONLINE three-probe cleanup case and exact open-attempt assertions. No extra production probes are introduced to satisfy the old assertion.
  • Fix [Bug]: CSV lookahead can swallow one-time storage read errors #30446 in the shared CSV parser: COMMENT lookahead and STARTING BY scanning must propagate non-EOF I/O errors. Previously, a one-time read error could be discarded and later reads could produce success. The narrow guards apply to both Read and ScanRecord, preserving normal EOF and unterminated final records. This adds no retry, state or persistent format change.
  • Before the correction, all four parser fault-injection cases and the boundary-reader error/cleanup case failed. An exact-main parser-source overlay also reproduced both legacy Read failures; this is parser-level evidence, not a full clean-main SQL reproduction.
  • Rebased onto official main 65bcea5d24610dde1a21bb9f4dea1efd82a8ce50, including perf(ci): scope SCA by Go dependencies and shorten freshness BVT #30442's shared mock PID fixture correction for the other coverage failure. This PR adds no runner-process changes.

Current Linux/x86 validation (Go 1.27.1, mo-cgo-test, matrixone_test, bounded GOMAXPROCS=2):

  • Full csvparser tests passed normally and under race (0.031s / 1.136s), including COMMENT/STARTING BY one-time I/O errors through both parser entrypoints and final-record EOF controls.
  • Full external tests passed normally and under race (35.741s / 36.668s), including the CI-named cleanup failure and the new boundary-reader storage-error/close-once regression. The corrected prescan parent test also passed with coverage instrumentation.
  • The public one-CN TestLoadCSVParallelNonStrictMultiline passed normally and under race (8.568s / 8.225s) after the error-propagation correction.
  • Runtime normal/race tests passed. Incremental golangci-lint across all six affected packages reports 0 issues; vet, formatting and diff checks passed. The repository molint command completed successfully; its diagnostics point to unchanged Arrow/plan/compile code outside this PR.
  • New remote CI remains pending after delivery. The earlier failed coverage run did not produce a repository-wide coverage verdict.

Planning benchmark: approximately 16 MiB, eight ranges, production parser configuration, one excluded warm-up followed by three measured rounds per input/method (BenchmarkNonStrictCSVBoundaryFraming, -benchtime=1x, measured -count=3). Every sample asserts identical boundaries and 16,056,320 bytes read, including read-ahead. Medians on Apple M4, GOMAXPROCS=10:

Input Read time ScanRecord time Read allocations ScanRecord allocations
Plain CSV 127.622 ms 54.555 ms 323 316
Escaped multiline CSV 184.686 ms 78.803 ms 1,761,926 309

Escaped-input allocated bytes drop from 21,130,072 to 2,337,472 per operation. These are warmed in-memory boundary-planning measurements; SQL throughput, remote storage latency and concurrent-load effects were not measured. Partition planning still adds a serial framing pass plus per-reader read-ahead and opens. Syntax fallback remains best effort for malformed files. The original #30378 is left open for reporter verification after merge.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added the kind/bug Something isn't working label Oct 16, 2026
@CLAassistant

CLAassistant commented Oct 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ iamlinjunhong
❌ loom


loom seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Oct 16, 2026
@iamlinjunhong
iamlinjunhong force-pushed the codex/loom/develop/7e1ad72b85b7fb288bfef5088fb2a95dc7e1fdf2e0d61ba24a0c4938e078cc6c branch from ce2d6da to 9ae2e83 Compare October 16, 2026 20:05
@XuPeng-SH

XuPeng-SH commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 9ae2e836d571f6382c60b6396fc83b1b801d381e

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 9ae2e836d571f6382c60b6396fc83b1b801d381e

Assessment: request_changes

Reviewed the complete six-file delta and its parser, compile, and reader consumers. Replaying the existing parser from confirmed record boundaries is a sound design, and focused correctness checks pass. Two actionable gaps remain: avoidable field decoding during planning and missing required SQL-entrypoint regression coverage.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

  • P2 pkg/sql/colexec/external/external.go:942: Parallel non-strict CSV loading scans records containing escaped field values to select boundaries.
    Impact: CSVParser.Read unescapes and materializes values that the boundary planner discards, adding allocation and CPU costs proportional to import size before workers start. Reuse the parser's record-framing implementation through an appropriate scanning operation without decoding field values.
    Evidence: A retained approximately 16 MiB, eight-range benchmark measured a median 190 ms and 1,334,943 allocations on the candidate. A diagnostic overlay using the same parser's readRecord routine measured 93 ms and 367 allocations with identical bytes read; the focused external boundary tests also passed. See candidate-probe.log, diagnostic-framing.log, and their overlays under the assigned diagnostic directory. These measurements isolate planning, not total LOAD throughput.

  • P2 pkg/sql/colexec/external/csv_nonstrict_boundary_test.go:183: Validation requirement: execute SQL LOAD DATA with PARALLEL 'true', STRICT 'false', multiple admitted ranges, and a quoted multiline field crossing a nominal split.
    Impact: The new integration test directly invokes ReadFileOffset and CsvReader, bypassing SQL admission and execution. Add and execute a public-path regression that proves multiple ranges are used and asserts complete values and exact row identities without omissions or duplicates.
    Evidence: The repository testing contract requires public-path proof for SQL-visible changes. The PR explicitly reports no SQL/frontend BVT execution. Existing load_data.sql coverage uses test_parallel.csv, which is 1,958,890 bytes and therefore falls below the 128 MiB parallel-admission threshold. The new sparse-file compile test also calls the compile helper directly. Consequently, the supplied green BVT statuses do not close this regression requirement.

Validation:

  • Preflight passed. Independently matched 192 native build inputs and seven retained library hashes to the current revision and verified the successful build receipt.

  • Focused Go tests passed with -count=1, -vet=all, and the supplied test-exec: 17 top-level tests and 89 total test/subtest passes across external, compile, and csvparser.

  • The retained multiline counterexample passed on the candidate and failed against the complete base overlay with 'unterminated quoted field', confirming the intended correction.

  • Compared candidate/base planning for ordinary and escaped CSV with two/eight ranges and a JSONLINE control. CSV adds a serial scan; JSONLINE retained its read volume. Ordinary SQL paths outside this splitter remain unchanged.

  • Source fingerprints, formatting, diff checks, overlay hashes, command receipts, and terminal logs were reconciled in /home/xupeng/.local/state/mo-bot/jobs/034a9f0a41929577ce72502e/attempt-1/evidence-audit.json. Source remained unchanged.

Limitations:

  • Performance probes used an in-memory ETL reader; SQL throughput, object-store latency, and concurrent-load effects were not measured.

  • Frozen CI reports successful UT, static analysis, and multi-CN BVT checks, but detailed CI logs and retained author validation artifacts were not supplied.

  • The linked issue body was absent from the supplied evidence.

@mergify

mergify Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-17 01:53 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-10-17 04:11 UTC · at f3f50b8e1645de1380f602bbe34ba3a0bbc0573d · squash

This pull request spent 2 hours 17 minutes 35 seconds in the queue, including 56 minutes 8 seconds running CI.

Required conditions to merge

Copy link
Copy Markdown
Contributor

独立合并后验证补充(2026-10-17,main a322466757b9b0165c59fbda565608653d923b2a,Linux/amd64、Go 1.27.1、匹配 CGo):

  • csvparser/runtime/external 完整普通及 race 测试通过;COMMENT/STARTING BY × Read/ScanRecord 四个一次性 I/O 错误注入场景和 external reader cleanup 断言实际执行通过。
  • 仓库 public-SQL multiline 回归通过:58 字节输入,两个实际区间 [0,39)、[39,EOF),完整值、转义及行身份断言通过。
  • 独立 272,192,894 字节引号 CSV(17,000 行,字段内换行,无唯一约束遮蔽重复)真实 SQL 导入:串行、严格并行、非严格并行空/default sql_mode 四条路径均通过;rows/distinct=17000、payload=272000000 字节、bad_tails=0、sum(id)=144508500。保持生产 128 MiB admission 阈值,fixture 本地 worker budget 明确为 2,并观察到两个实际区间;非严格边界 136108404。

#30378、#30446 已分别附证据并转给 @Ariznawlll。

This branch was previously deployed

1 inactive deployment
ci — c24a1ecc Deployed Oct 17, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CSV lookahead can swallow one-time storage read errors

4 participants