Skip to content

fix(frontend): preserve CSV row boundaries in split OUTFILE - #29778

Merged
XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
Lundomn:fix/29761-csv-split
Oct 9, 2026
Merged

XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
Lundomn:fix/29761-csv-split

Conversation

@Lundomn

@Lundomn Lundomn commented Oct 9, 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:

Closes #29761

What this PR does / why we need it:

CSV SELECT ... INTO OUTFILE ... SPLITSIZE must split at complete record boundaries. The writer now carries row counts and collects row-end offsets only when a finite size limit requires them. It greedily groups records that fit, includes the first record after rotation in the new file's write, and keeps a single oversized record intact. Unlimited CSV keeps one whole-batch write, while JSONLINE and Parquet behavior stays unchanged. The ordered export and data-branch consumers use the same payload metadata. Empty encoded records remain counted without creating empty tail files, and write or rotation failures preserve completed progress.

Validation on base 908166384d32e378a72cc3b5ef9e7075603c4e81, head 9c875407a4ee15d33026865dadf4f4b468279a9b:

  • ./.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=180s ./pkg/frontend — passed (24.386s package time).
  • ./.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=10m -run '^(Test_writeToCSVFile|TestExportCSVBatchSplitPreservesRows|TestExportCSVEmptyEncodedRecordDoesNotCreateTrailingFile|TestExportCSVBatchSplitExactFitAndOversizedRecord|TestExportCSVFinalDrainPreservesOutOfOrderBatchMetadata|TestExportCSVUnlimitedBatchUsesSingleWrite|TestConstructByteOmitsRowOffsetsWhenCSVIsUnlimited|TestExportCSVFiniteSplitGroupsRowsIntoOneWrite|TestExportCSVFiniteSplitCoalescesRowsAfterRotation|TestExportCSVBatchSplitsAreIndependentOfBatchDistribution|TestExportCSVBatchWriteErrorPreservesCompletedProgress|TestExportCSVRotationErrorsPreserveCompletedProgress)$' ./pkg/frontend — 12 focused tests passed (4.031s).
  • Frontend incremental lint using repository .golangci.yml and golangci-lint v2.14.0 — 0 issues.
  • CGO_ENABLED=1 GOWORK=off go vet -mod=readonly ./pkg/frontend with the repository CGo include/link/runtime paths — passed without diagnostics.
  • make build-with-prebuilt-native — passed using verified, platform-matched native artifacts.
  • Isolated SQL/BVT for test/distributed/cases/stage/issue_29761_splitsize.sql — two runs on the same task-owned service passed 23/23 statements each. The case verifies three 48-byte split files, ordered payload values, and cleanup.

The 8,192-row producer benchmark measured 65,541 fewer B/op (−2.53%) for unlimited CSV. A spy writer reduced the 32 KiB case from 19 data-write calls to 10 while retaining 9 rotations; this spy does not measure pipe, file-open, or storage I/O. A five-sample finite-helper microbenchmark improved 31.7% at high limit and 38.3% at 32 KiB, but has no 95% confidence interval and measures helper CPU only. Earlier producer samples showed a possible unlimited-CSV CPU increase (+7.5% in the bounded reverse-order run; +17.3% in the initial paired run) while host load changed, so the measurements cannot attribute or rule out a small CPU regression. No end-to-end throughput improvement is claimed.

A single CSV record may exceed SPLITSIZE so its contents remain intact. Full repository CI has not been run locally.

@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 →

@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.

Deep review of 9c875407a4ee15d33026865dadf4f4b468279a9b against 908166384d32e378a72cc3b5ef9e7075603c4e81: approve. No blocking finding in all five changed files and their export/data-branch consumers.

The existing CSV encoder is the right owner of record-end offsets: quoted newlines cannot safely be rediscovered by splitting encoded bytes. Carrying those offsets through the existing ordered batch payload preserves one writer/order authority. hasCSVData has a distinct purpose from Rows/CurFileSize: a header is not data, and an accepted zero-byte record is still a row. It prevents empty leading/tail rotation while permitting one oversized record. Offsets are omitted for unlimited CSV, and the actual write/rotate operations still use the existing file/pipe owner.

Adversarial boundaries checked: header plus exact-fit/oversized row, embedded newline/comma, empty records around an oversized record and across batches, out-of-order completion, and first write after rotation. These map to the real-file CSV-parser tests, batch-distribution comparison, and ordered final drain. Write/close/open failure tests preserve completed per-file progress without marking a partially written batch complete; call-site tracing confirms errors terminate the export rather than retrying the whole partial batch. The data-branch final-drain path reaches the same batch writer. JSONLINE dispatch bypasses CSV metadata and Parquet keeps its existing finalizer.

Evidence reused: the exact-head author records full frontend UT, the 12 focused race tests, and two same-service 23/23 SQL/BVT runs. Exact-head CI 37912137865 succeeds; whitespace check passes. The three-row BVT verifies file names/sizes, reloads every file and checks exact ordered values and cleanup. No earlier substantive review comments exist. No additional broad rerun was needed after mapping these cases to the changed boundaries.

Scope/quality: implementation +85/-10 across two files; tests/BVT +548/-0 across three files; no documentation-file delta. Tests have distinct behavioral or failure oracles, without sleeps or large fixtures. Finite splitting adds a linear row-offset scan and one offset per row, but coalesces records into writes; unlimited CSV avoids that allocation/scan. The disclosed microbenchmarks do not establish end-to-end throughput, and the noisy unlimited-CSV CPU samples do not justify claiming a CPU improvement.

@mergify mergify Bot added the queued label Oct 9, 2026
@mergify

mergify Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-09 11:51 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-09 12:09 UTC · at b95f842cb367fc2dd5dfc13a468726f5a4b217f1

This pull request spent 17 minutes 58 seconds in the queue, with no time running CI.

Reason

Pull request #29778 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

This branch had an error being deployed

1 failed deployment
ci — b95f842c Deployed Oct 9, 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 size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CSV OUTFILE SPLITSIZE creates a header-only file and writes the full batch to an oversized file

3 participants