Repository navigation
fix: csv dump corrupts literal \N and NULL text values (matrixorigin/matrixone#30568) - #63
Conversation
In -csv mode, SQL NULL and the literal text value \N were written as the same bytes, and a literal NULL word was written unquoted; LOAD DATA then restored all of them as SQL NULL (silent data loss, MODUMP SUCCESS notwithstanding). - distinguish SQL NULL by nil RawBytes, not by string content, so a text \N is escaped to \\N and can no longer collide with the NULL marker - write CSV records with explicit quoting instead of encoding/csv: a literal NULL word is forced into ".." quotes, which both MatrixOne and MySQL read back as the string 'NULL'; the SQL NULL marker \N stays unquoted - escape backslash (and ',' under -enable-escape) exactly once instead of the escapeChars/escapeString double escape, and keep binary (non-UTF-8) values byte-identical while escaping and quoting
… delimiter Regression fixes for the CSV writer switch in the previous commit: - quote fields whose first rune is whitespace (as encoding/csv did): unquoted whitespace-only records are skipped as empty lines by older loaders, silently dropping rows on restore - checkFieldDelimiter now rejects '"', '\r', '\n' (and NUL/RuneError), matching encoding/csv's delimiter rule, so an unusable delimiter fails fast instead of producing a successful-but-unrestorable dump
XuPeng-SH
left a comment
There was a problem hiding this comment.
APPROVE at 14475e6 (base 324c33d).
The CSV framing boundary now distinguishes SQL NULL structurally from text, escapes bytes once, forces quoting for literal NULL, and preserves invalid UTF-8. Replacing encoding/csv is justified by the required field-quoting contract; obsolete regexp escaping/state is removed. Full production/test delta reviewed, including delimiter rejection and per-row state reuse.
Independent validation: all 47 package test/subtest events pass; build/vet/gofmt/diff checks pass. Fifteen keyed text/NULL/control cases restore identically twice for default delimiter, pipe delimiter and enable-escape; three binary cases also restore identically twice. The broader initial corpus uncovered two existing loader/export gaps: a one-column empty-string record is lost, and a pure CR value restores as empty. Both were independently reproduced on exact clean base 324c33d; they are disclosed here, not counted as regressions introduced by this fix. No universal CSV round-trip claim is made.
A focused writer microbenchmark shows improved medium/large-field CPU time but increased allocation bytes; no zero-cost claim is warranted. Merge with #57 must retain Rows.Err() as well as Flush() errors; the two current heads conflict in that boundary and tests. This approval covers the scoped NULL/escaping fix at this exact head. Live tests used an existing prebuilt service, not latest-main validation. No subagents or source edits.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
Summary
In
-csvmode,mo-dumpsilently turned two kinds of legal text values into SQL NULL on restore (matrixorigin/matrixone#30568):\Nwas exported as the same raw bytes\Nthat SQL NULL uses, becauseescapeStringspecial-caseds == "\\N"and could not tell the NULL marker apart from data.LOAD DATAreads the raw field\Nas NULL (even inside quotes), so the text value was lost.NULLwas written unquoted, and both MatrixOne and MySQL read an unquotedNULLword as SQL NULL whenFIELDS ENCLOSED BYis non-empty.Restore exited 0 and the dump was marked
MODUMP SUCCESS, i.e. silent data loss on backup/restore of text columns.Changes
RawBytes, never from string content, so a text\Nis escaped to\\Nand can no longer collide with the NULL marker on the wire.writeCsvRecord/csvFieldNeedsQuote) instead ofencoding/csv: fields containing the delimiter,",\r,\n, or equal toNULL(case-insensitive) are quoted, so a literalNULLrestores as the string'NULL'(MySQL-documented behavior for quoted NULL); the SQL NULL marker\Nstays unquoted.,under-enable-escapefor string columns) is escaped a single time, replacing theescapeChars+escapeStringdouble escape that corrupted values likea,bintoa\,b.Tests
cmd/mo-dump): table-driven cases for NULL, text\N/\\N/NULL/null, comma, double quote, LF, empty string, binary bytes,|delimiter, and-enable-escape.-csv+LOAD DATA LOCAL INFILErestore, compared per row viaHEX(v)/v IS NULL):,delimiter — round-trip identical, including the issue's exact repro rows-csv-field-delimiter '|'— identical-enable-escape=true— identical (a,bstaysa,b)0xFF, embedded\\,"and LF — byte-identicalFixes matrixorigin/matrixone#30568