Repository navigation
fix(outfile): accept FIELDS ESCAPED BY/LINES STARTING BY and reject non-UTF-8 Parquet exports (#30710) - #31100
Conversation
… INTO OUTFILE (matrixorigin#30710) The OUTFILE grammar only accepted TERMINATED BY/ENCLOSED BY in a fixed order, rejecting two clause families that LOAD DATA accepts end to end (serialized as issue matrixorigin#30754). Reuse the LOAD field_item productions for the OUTFILE FIELDS clause (any order, merged over the historical OUTFILE defaults) and mirror load_lines for the LINES clause, so both statements from matrixorigin#30754 parse and keep their semantics. The writer now honors them byte-exactly: LINES STARTING BY prefixes every data record while the CSV header stays unprefixed, so LOAD's startingBy line filter skips the header instead of importing it; the FIELDS ESCAPED BY byte (including '' disabling escaping) reaches the existing escaping path. STARTING BY containing the record terminator is rejected up front with the same error text LOAD's csvparser reports. ExportParam.String() tolerates the now-optional EscapedBy and renders STARTING BY. Parser/serialize round-trip tests pin the clause matrix; writer tests round-trip output through LOAD's csvparser; a distributed BVT case covers the exported bytes and LOAD round-trip.
…trixorigin#30710) A Parquet String() column is UTF-8 by definition, but the export wrote VARCHAR-family bytes verbatim, reporting success for a file that MatrixOne's own parquet loader then refuses (ERROR 20301, invalid UTF-8 value for VARCHAR). NewParquetWriter now classifies every column whose values land in a String() node with string semantics, and writeBatchChunk rejects the first invalid value with the same error shape and code the loader reports, before any row group reaches the file. Binary-declared columns (BINARY_FLAG: VARBINARY/BINARY/binary BLOB) keep the loader's exemption and round-trip losslessly. Unit tests pin the VARCHAR/TEXT/CHAR rejection message, the no-bytes-emitted behavior, the valid-UTF-8 control, the binary-flag exemption, and the column predicate; a distributed BVT case replays the issue scenario and all controls through LOAD DATA.
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Verification evidence (head
|
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: f594e545ccaaef8957e0cc2217cb98e37071c046
Assessment: request_changes
Reviewed the complete delta and affected callers. Grammar reuse and Parquet validation fit the existing owners, but the new prefix/header policy can silently import header fragments as data.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1
- P2
pkg/frontend/export.go:574: Use LINES STARTING BY with the default header enabled when the prefix occurs in a column name. For example, export SELECT 'alpha' AS name with LINES STARTING BY 'n', then LOAD using matching clauses.
Impact: LOAD imports an extra 'ame' row alongside 'alpha', violating the claimed automatic header-skipping contract. Validate header/prefix collisions before opening the file or adopt an unambiguous header policy, and add a SQL regression.
Evidence: The SQL probe produced bytes "name\nn"alpha"\n" and loaded [["alpha"],["ame"]]. csvparser.readRecord uses bytes.Index on the entire line, so leaving the header unprefixed does not guarantee exclusion. Reproduction: review_pr31100_test.go, sql-probes.log; receipt checks/1792936494381538125-3.json.
Validation:
-
Preflight passed. All 192 native build inputs matched retained artifacts, and the repository provenance verifier passed.
-
Parser regeneration matched the candidate byte-for-byte. All pkg/sql/parsers/... tests and focused frontend export tests passed; receipts 1792936071682352889-3, 1792936127612800242-3 and 1792936181442917166-3.
-
SQL probes passed CSV prefix/custom-escape round trips with multiline values and NULLs. The header-collision assertion failed as described above.
-
Parquet SQL probes passed valid text/binary round trips, early invalid UTF-8 rejection, late failure without an unsplit file, and subsequent successful export. All 147 retained split files loaded successfully, containing rows 1–8967; receipt 1792936561938782819-3.
-
An initial diagnostic error-message expectation had incorrect capitalization; correcting it and rerunning the Parquet scenario passed. This was not a product failure.
-
Commands, source fingerprints, exit receipts and logs were reconciled in /home/xupeng/.local/state/mo-bot/jobs/b92277cc81af58436b7b80a6/attempt-1/review-audit.json. Source remains unchanged.
Limitations:
-
Author runtime evidence names an earlier commit; it was not treated as current-head validation. Raw CI logs and separate linked-issue bodies were absent.
-
SQL validation used the local single-CN fixture, not distributed BVT replay.
-
Performance was assessed structurally, without benchmarks: prefix work scales with emitted bytes and UTF-8 validation scans textual Parquet values; ordinary non-export execution paths are unchanged.
iamlinjunhong
left a comment
There was a problem hiding this comment.
Reviewed head f594e545ccaaef8957e0cc2217cb98e37071c046 against base 12eeeb0205b5e87faef48660ddbcd8cb5e18baea, including all 13 changed files, generated parser consistency, CSV writer/loader paths and Parquet validation/finalization. Two nonblocking correctness findings remain; no confirmed P0/P1. Event: COMMENT.
-
[P2] Do not assume an unprefixed header is excluded by STARTING BY —
pkg/frontend/export.go:574–579.Trigger:
SELECT 'alpha' AS name INTO OUTFILE 'out.csv' LINES STARTING BY 'n'with the default header, then LOAD into a one-column VARCHAR table using the matching clauses. The output isname\nn"alpha"\n.openNewFilewrites the header unchanged, whilecsvparser.readRecordsearches the entire line withbytes.Index, rather than requiring the prefix at offset zero. It therefore consumes theninnameand importsameas an extra row beforealpha. The same ambiguity recurs for split-file headers. Validate header/prefix collisions before opening a file, or use an unambiguous header policy, and cover a prefix occurring inside a column name. The existing header test uses only the noncolliding>>prefix. -
[P2] Preserve literal NULL-marker text with custom escape bytes —
pkg/sql/parsers/dialect/mysql/mysql_sql.y:6958–6959.Trigger: export a VARCHAR containing the two bytes
5C4E(literal backslash followed byN) withFIELDS ESCAPED BY '#' HEADER 'false', then LOAD with the same fields configuration. The newly accepted escape setting reachesaddEscapeToString, which leaves that value unchanged and writes a quoted"\N"record. LOAD'snewCSVParserFromReaderstill configures aNulllist containing literal\Nand leavesQuotedNullIsTextfalse;unescapeStringtherefore returnsIsNull=true, silently replacing the string with SQL NULL. With the previous/default backslash escape, the writer emits two backslashes and the loader correctly preserves the non-NULL value. This is newly reachable through the OUTFILE grammar, and violates the explicit custom-escape round-trip acceptance criterion. Ensure literal marker text and SQL NULL remain distinguishable and add a regression including both values; the current custom-escape tests cover NULL but not literal\N.
Validation:
- Regenerated
mysql_sql.gowith the repository goyacc in a temporary directory and ran gofmt: byte-identical to the committed file, with no conflicts reported. - Ran isolated probes using an unchanged copy of
csv_parser.goand unchanged selected CSV writer helpers. They reproduced both findings; the noncolliding-prefix and default-backslash controls preserved the expected rows/values. Only error construction, bytes-to-string conversion and the configuration limit used minimal dependency shims. These probes did not run a SQL server or storage layer. - Attempted focused Go package tests for csvparser, MySQL parsing and tree serialization. Compilation was blocked by missing native dependency headers (
roaring.h,xxhash.h,usearch.h,jemalloc.h); these tests are not reported as passing. Full frontend/runtime/BVT tests were not rerun locally. git diff --checkand the Loom PR artifact check passed. Source remains unchanged.- Dispatched checks: all 30 completed (14 success, 14 skipped, 2 neutral). Live read-only metadata confirms the same head/base, mergeable=true, mergeable_state=behind.
History: no previous review from this reviewer is present. Review 5643569067 independently reported the header collision; its severity does not warrant REQUEST_CHANGES under this review policy. The author's verification comment predates that review and is not a response to it. No corresponding author reply is present in the reviewed conversation/review comments, so the P2-reply approval exception does not apply.
…matrixorigin#30710) LOAD's startingBy line filter only skips a line entirely when the prefix is absent from it; a line merely containing the prefix keeps its remainder as a record. The CSV header is written unprefixed so the filter skips it, but a column name containing the prefix (e.g. `name` with LINES STARTING BY 'n') would keep the mangled remainder as a data row on LOAD. Detect the collision exactly the way the reader scans the raw line bytes and reject the statement before any file is opened, with HEADER 'false' as the documented escape hatch. Adds UT coverage for single-cell and terminator-spanning prefixes and a BVT probe replaying the reported scenario.
|
Fixed the actual-following-delimiter review finding in f2132ef. Before the fix, a real local Docker OUTFILE/LOAD probe reproduced the reported corruption: The shared replay now uses the exact emitted boundary and explicit last-column position from both writers. Non-final fields include an empty next-field witness and must decode to precisely the expected fields and one record. This catches suffix/delimiter overlap, rejects unsafe NULL framing before publishing a row, and retains safe last-column NULLs and default-backslash controls. It preserves the existing rejection policy and error class rather than changing NULL quoting policy. Extended the existing regression suites: NULL first/middle/last, Validation on Go 1.27.1 / Linux arm64:
New exact-head CI and reviewer re-review are pending. No review state or branch protection was changed. |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: f2132ef1fc5c07458f403c053d19f7c89ae4671c
Assessment: approve
Reviewed the complete 15-file delta and frozen discussion. Grammar reuse, shared CSV formatting, pooled LOAD-parser validation and Parquet UTF-8 validation fit the existing owners. Prior findings are resolved, including NULL overlap with the actual following delimiter. The added export-local validation cost is justified; no actionable finding remains.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1
Validation:
-
Evidence retained under /home/xupeng/.local/state/mo-bot/jobs/7ba59d4096527feed07be24a/attempt-1. review-audit.json reconciles 12 command/source/exit receipts with logs; final audit receipt 1793078036963108175-4 passed. Source remains unchanged.
-
Read all 45 raw discussion items and their index entries. discussion-assessment.json accounts for all 43 nonempty items exactly once and reconciles prior findings with author responses and current evidence.
-
Isolation preflight passed. Retained native build qualified against all 200 current native inputs and seven output hashes. Focused native frontend, grammar and tree regression tests passed.
-
Generated mysql_sql.go matches regeneration byte-for-byte. Independent complete-row checks passed 660 accepted round trips and 76 explicit rejections. The exploratory identical-separator failure was reproduced with merge-base helpers and classified as preexisting.
-
Exact pooled-parser race test passed 100 repetitions. The full frontend race run had one read-only-fixture failure and no race report; that exact test passed with only its output filenames relocated, preserving production code and assertions.
-
Helper benchmarks measured ordinary text at 35.9–42.8 ns versus 33.9–35.9 ns at base, and default NULL at 131–216 ns versus approximately 12 ns, with zero amortized allocations. Parquet adds a text-byte validation scan without another text copy.
-
Reused frozen exact-head successful build, UT, SCA and active BVT statuses, plus the author's current-head report of two 194/194 SQL result/metadata runs, as supporting public-path evidence.
Limitations:
-
No live SQL server or distributed run was repeated locally. Raw author/CI execution logs and separate linked-issue bodies were not supplied.
-
The unmodified full frontend race command failed on the read-only fixture; it is not reported as a passing command. Recovery evidence is recorded separately.
-
Benchmarks measure formatter cost, not end-to-end SQL throughput. Disabled escaping retains documented verbatim semantics; identical field/record separators retain their preexisting limitation.
🚫 Left the queue1 h 1 min in the queue, with no time running CI. So far
Reason The pull request can't be updated
Hint You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. Requeued — the merge queue status continues in this comment ↓. Times in UTC · dashboard · how the merge queue works |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reconsidering my previous approval: the two underlying defects are real, but the current solution still leaves a correctness gap and adds avoidable work to a common export path.
-
Binary Parquet schema / incomplete UTF-8 contract.
valueRequiresValidUTF8exemptsBINARY_FLAG, butbuildParquetNodestill mapsMYSQL_TYPE_VAR_STRINGandMYSQL_TYPE_STRINGtoparquet.String()regardless of the flag. Actual VARBINARY/BINARY metadata uses those types withBINARY_FLAG. Thus arbitrary bytes such as61 ff 62are written under a UTF-8 logical type: MO can round-trip the bytes, but an external consumer treating the schema as UTF-8 can fail. I independently reproduced this using the same parquet-go schema/writer and PyArrow: materializing the String-schema value raisesUnicodeDecodeError, while a BYTE_ARRAY binary-schema control reads successfully. This schema bug predates the PR, but the new test only checks success/MO round-trip and the PR claims the resulting binary files are valid. Please address the schema/contract consistently and add a schema plus external-consumer or equivalent independent regression check. The reproduction was library-level, not a live MO SQL run. -
Repeated NULL replay in the default CSV hot path.
formatOutputNullreplays the same marker through the LOAD parser for every NULL, even with ordinary default framing. The result is determined by the statement configuration and actual following boundary, so repeating it per row is unnecessary. The prior review's helper benchmark onf2132efmeasured approximately 131–216 ns versus 12 ns at base for a default NULL; that is not an end-to-end throughput measurement, and the CSV parser changed after that head. Please avoid repeating invariant checks (e.g. a safe default fast path or a lazy per-boundary result), preserve errors when a NULL is actually encountered, and measure the current head with representative NULL-heavy and ordinary exports. -
Existing OUTFILE compatibility. The new framing checks reject delimiters that existing OUTFILE statements could previously emit, for example a field delimiter beginning with a double quote, solely because MO LOAD rejects them. OUTFILE consumers need not use MO LOAD. Please explicitly settle the intended compatibility/round-trip contract and either avoid broadening the restriction or document and test the deliberate behavior change on existing syntax.
The real corruption cases behind the extra CSV checks should remain covered, but please also review the duplicated LOAD configuration and the large test matrix for opportunities to share the authoritative configuration and consolidate redundant setup. The PR description should reflect the actual writer validation changes. Current-head frontend UT was not rerun locally because the matching CGo artifacts were unavailable.
|
Implemented the latest review in 655fdbf.
Validation:
NULL-heavy formatting is 61–68% faster in these samples; ordinary controls range from -0.8% to +12.2% elapsed time with unchanged allocations. Initial sequential samples had even greater ordinary variance (+19.6–48.5%); pairing reduced but did not eliminate shared-host uncertainty. These are in-memory formatting measurements (batch includes duplication/cleanup), not full file/network throughput or a no-regression certification. Latest old-head CI diagnosis, from downloaded artifacts of job 122067530681: only three failures, all in vector_hnsw_delete_insert.sql—both serving-generation waits return 0 after 120 s, and the nearest-neighbor query returns old id 777 rather than 2001. Coverage then explicitly reports a missing/incomplete required producer profile; no coverage verdict was calculated. No claim that this HNSW failure is pre-existing without clean-baseline proof, and no unrelated HNSW code or assertions changed. The old Mergify cancellation separately cites App workflow-write permission; no permissions/workflow settings were changed. Pushed normally. New-head CI is pending, not counted as passed. |
|
Updated the branch against main
Validation: full frontend, external, MySQL parser and tree tests pass; focused CSV/NULL/Parquet writer tests pass under race. A fresh two-CN+proxy service passes HNSW 63/63 and the CSV/Parquet SQL regressions 240/240, each twice on the same instance with cleanup verified. Services are stopped and joined afterward. The three implementation findings from the earlier review remain covered: binary Parquet fields use unannotated BYTE_ARRAY; NULL replay is lazy and statement-scoped; deliberate existing-syntax delimiter restrictions are documented and tested. The canonical parser generator resolved the main-merge conflict. Fresh CI on the updated head is pending; the prior formatting benchmark still does not certify zero end-to-end performance regression. |
|
Follow-up on current head The sole failing prerequisite is SCA job 122147817239. Its GitHub failure annotation is: “The self-hosted runner lost communication with the server.” The Static Code Analysis step has no terminal result and its post-job steps never ran. Direct log downloads, including a fresh request, return BlobNotFound/404, so there is no completed SCA log establishing a new lint/code error. Whether the runner loss was caused by networking, host resource pressure or runner termination is not established. I retried only this failed job on the unchanged head. No speculative production fix, empty commit, lint suppression, timeout increase or workflow/permission change was made. The retry result is pending, not green. There is no newer reviewer finding than review5663628758. Its three requests remain addressed by the existing code and tests: binary Parquet columns use unannotated BYTE_ARRAY consistently with validation; NULL replay is lazy and cached separately per actual boundary; and the deliberate existing-syntax framing restrictions are documented and tested. The implementation and validation details are in the prior correction reply. The branch is currently mergeable; a fresh reviewer assessment is still needed, not self-assumed approval. |
|
Resolved the merge conflict by merging main Main now owns the HNSW freshness test fix. Both its SQL and result file are adopted byte-for-byte, including the scoped all-CN freshness interval and restoration. The earlier PR-specific cache-eviction workaround is removed rather than layered on top; the test no longer appears in this PR's diff against main. Validation used five separate The previous head |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: adfdba35ae09414a2f96b671b293b50598466075
Assessment: approve
Reviewed the complete 17-file delta and discussion. Prior concerns are resolved: binary Parquet schemas use BYTE_ARRAY, NULL validation is cached per boundary, and LOAD configuration has one owner. The deliberate delimiter compatibility restrictions are documented and tested. No actionable findings remain.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1
Validation:
-
38 focused tests passed under race across frontend, external, MySQL parser, tree and csvparser.
-
Full frontend race suite: 2,702 tests passed; one existing test skipped. NULL-cache and parser-pool tests each passed 100 race repetitions.
-
Canonical parser regeneration matched byte-for-byte; diff checks passed; source remained unchanged.
-
All 53 discussion keys reconciled in discussion-assessment.json. Current-head CI reports successful build, UT, SCA, coverage and both active multi-CN BVT legs.
-
review-audit.json maps 11 checks to source fingerprints, exit receipts and retained logs. Final audit receipt checks/1793115638477083107-4.json passed. Artifacts: /home/xupeng/.local/state/mo-bot/jobs/51f9bb95ffdc69dc6fd6caea/attempt-1.
Limitations:
-
Full frontend race used a test-only overlay relocating two fixture output filenames; production code and assertions were unchanged.
-
SQL topology and throughput measurements were not rerun locally. Author reports and frozen CI statuses are supporting evidence; their raw execution logs were unavailable.
🚫 Left the queue13 min in the queue, with no time running CI. So far
Reason Pull request #31100 has been dequeued Queue conditions are not satisfied:
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. Requeued — the merge queue status continues in this comment ↓. Times in UTC · dashboard · how the merge queue works |
|
Resolved the merge conflicts in
Validation on the new merge commit, Go 1.27.1 Linux/arm64:
The preceding reviewed head's full CI passed. Mergify dequeued it because of the merge conflict, not a failing UT/SCA/BVT. New merge-head CI is pending, not counted as green. Earlier race, benchmark and independent-process SQL evidence remains historical supporting evidence; no fresh race/topology/performance run is claimed here. No workflow, permission, timeout, assertion or expected-result suppression was used. Delivery note: Git transport became unavailable during the final push. The final commit was published through GitHub Git Data API instead, checking uploaded blob hashes, the complete tree hash and the exact commit SHA before a non-forced ref update. Remote readback confirms the same locally validated |
🚫 Left the queue1 h 8 min in the queue, with no time running CI. So far
Reason Pull request #31100 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.
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. Merge conditions: 2 of 3 metThis pull request
The batch, tested in place
Tick the box to put this pull request back in the merge queue (same as
Times in UTC · dashboard · how the merge queue works |
|
mo-bot review · Commit: Review belongs to an older commit; it is not a review of the current head. |
|
All required checks are green on head Approvals held: Requesting the Mergify queue for |
What type of PR is this?
Which issue(s) this PR fixes:
issue #30710 (consolidates #30754)
What this PR does / why we need it:
Fix two defects in SELECT INTO OUTFILE: rejected FIELDS ESCAPED BY / LINES STARTING BY syntax, and successful Parquet exports whose text contains invalid UTF-8.
Compatibility limits are deliberate, including for existing OUTFILE syntax: delimiters beginning with double quote, CR, LF, NUL or an invalid rune are rejected before opening the file, even without either new clause. For example,
FIELDS TERMINATED BY '"|' ENCLOSED BY ''no longer emits a file for an external-only consumer. Ambiguous enclosure/terminator and prefix/terminator combinations are also rejected. This is not a blanket unchanged-writer or universal-round-trip claim; disabling escaping can still emit unprotected separators. Details and alternatives: OUTFILE framing contract.Validation:
-nmode: HNSW 58/58 and CSV/Parquet 240/240 pass twice via the proxy, and twice via direct CN2. Account/user/global/database cleanup is checked after each run; all owned processes are stopped and joined. Earlier-launchchecks used multiple CNs inside one process and are not independent-cache validation.66c9e7624e, preserving both its bounded strict-CSV-probe constructor and this PR's shared LOAD configuration, and regenerating the SQL parser from the combined grammar, including the newly merged integer-literal precision handling. The previous reviewed head's full CI is green; new merge-head CI is pending. The upstream HNSW freshness fixture remains unchanged by this PR; no redundant cache-eviction workaround is retained.