Skip to content

Align the default field separators for the export table and load data. - #22570

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
gouhongshen:fix_load_data
Sep 26, 2025
Merged

mergify[bot] merged 3 commits into
matrixorigin:mainfrom
gouhongshen:fix_load_data

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Sep 26, 2025 •

Copy link
Copy Markdown
Contributor

User description

What type of PR is this?

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

Which issue(s) this PR fixes:

issue ##22565

What this PR does / why we need it:

Align the default field separators for the export table and load data.


PR Type

Bug fix


Description

  • Standardized default field separators across export and load operations

  • Replaced hardcoded separators with centralized constants

  • Added comprehensive test for export-load roundtrip functionality


Diagram Walkthrough

flowchart LR
  A["Hardcoded separators"] --> B["Centralized constants"]
  B --> C["External parser"]
  B --> D["Load data binding"]
  C --> E["Consistent behavior"]
  D --> E
Loading

File Walkthrough

Relevant files
Enhancement
update.go
Define default field separator constants                                 

pkg/sql/parsers/tree/update.go

  • Added three new constants for default field separators
  • DefaultFieldsTerminated set to comma
  • DefaultFieldsEnclosedBy and DefaultFieldsEscapedBy defined
+6/-0     
Bug fix
types.go
Use centralized separator constants in CSV parser               

pkg/sql/colexec/external/types.go

  • Replaced hardcoded tab separator with comma constant
  • Updated to use centralized default separator constants
  • Changed from \t to tree.DefaultFieldsTerminated
+3/-3     
bind_load.go
Apply default constants in load data binding                         

pkg/sql/plan/bind_load.go

  • Replaced hardcoded separator values with constants
  • Updated terminated, enclosedBy, and escapedBy assignments
  • Ensures consistency with export operations
+3/-3     
Tests
load_data.sql
Add export-load roundtrip test case                                           

test/distributed/cases/load_data/load_data.sql

  • Added comprehensive roundtrip test case
  • Tests export to CSV and reload functionality
  • Includes vector data types and various column types
+19/-0   
load_data.result
Update test results for roundtrip validation                         

test/distributed/cases/load_data/load_data.result

  • Added expected results for new test case
  • Shows successful roundtrip with 3 records
  • Validates data integrity after export-load cycle
+17/-0   

@qodo-code-review

Copy link
Copy Markdown

You are nearing your monthly Qodo Merge usage quota. For more information, please visit here.

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

22565 - PR Code Verified

Compliant requirements:

  • Align the default delimiter used by INTO OUTFILE with the default delimiter expected by LOAD DATA INFILE.
  • Ensure users can export a table to CSV using defaults and then successfully reload it with LOAD DATA using defaults (roundtrip).
  • Provide regression tests demonstrating the export-load roundtrip succeeds without specifying custom separators.

Requires further human verification:

  • Verify behavior across different clients and environments (e.g., mysql client options, locale) to ensure defaults are consistently applied.
  • Confirm backward compatibility for users relying on previous defaults (tab vs comma) and document any behavioral change.
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Behavior Change

Default escaped-by changed from NUL to backslash; confirm this does not regress parsing of previously working files and matches OUTFILE defaults.

terminated := tree.DefaultFieldsTerminated
enclosedBy := []byte(tree.DefaultFieldsEnclosedBy)
escapedBy := []byte(tree.DefaultFieldsEscapedBy)
API Surface

New exported defaults constants; ensure no duplicate or conflicting defaults exist elsewhere and that comments/docs note intended global defaults.

const (
	DefaultFieldsTerminated = ","
	DefaultFieldsEnclosedBy = "\""
	DefaultFieldsEscapedBy  = "\\"
)
Consistency

Reader defaults now use centralized constants; verify all other CSV readers/writers in codebase also pull from the same constants to avoid drift.

fieldsTerminatedBy := tree.DefaultFieldsTerminated
fieldsEnclosedBy := tree.DefaultFieldsEnclosedBy
fieldsEscapedBy := tree.DefaultFieldsEscapedBy

@qodo-code-review

qodo-code-review Bot commented Sep 26, 2025 •

Copy link
Copy Markdown

You are nearing your monthly Qodo Merge usage quota. For more information, please visit here.

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
✅ Prevent panic with empty escape character
Suggestion Impact:The commit initializes escapedBy to []byte{0} instead of the default value, aligning with the intent to handle an empty escape character and avoid using the default escape when ESCAPED BY '' is specified.

code diff:

 	terminated := tree.DefaultFieldsTerminated
 	enclosedBy := []byte(tree.DefaultFieldsEnclosedBy)
-	escapedBy := []byte(tree.DefaultFieldsEscapedBy)
+	escapedBy := []byte{0}
 	if stmt.Param.Tail.Fields != nil {

Add an else block to correctly handle ESCAPED BY '' by setting escapedBy to
[]byte{0}, fixing a bug where this option was being ignored.

pkg/sql/plan/bind_load.go [159-174]

 	escapedBy := []byte(tree.DefaultFieldsEscapedBy)
 	if stmt.Param.Tail.Fields != nil {
 		if stmt.Param.Tail.Fields.EnclosedBy != nil {
 			if stmt.Param.Tail.Fields.EnclosedBy.Value != 0 {
 				enclosedBy = []byte{stmt.Param.Tail.Fields.EnclosedBy.Value}
 			}
 		}
 		if stmt.Param.Tail.Fields.EscapedBy != nil {
 			if stmt.Param.Tail.Fields.EscapedBy.Value != 0 {
 				escapedBy = []byte{stmt.Param.Tail.Fields.EscapedBy.Value}
+			} else {
+				// handle ESCAPED BY ''
+				escapedBy = []byte{0}
 			}
 		}
 		if stmt.Param.Tail.Fields.Terminated != nil {
 			terminated = stmt.Param.Tail.Fields.Terminated.Value
 		}
 	}

[Suggestion processed]

Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies a logic bug introduced by the PR where specifying ESCAPED BY '' would be ignored, causing the default escape character to be used instead. This fixes incorrect behavior for a valid user-specified option.

Medium
  • Update

@mergify mergify Bot added the kind/bug Something isn't working label Sep 26, 2025
@mergify mergify Bot added the queued label Sep 26, 2025
mergify Bot added a commit that referenced this pull request Sep 26, 2025
@mergify
mergify Bot merged commit 0f91bf9 into matrixorigin:main Sep 26, 2025
@mergify mergify Bot removed the queued label Sep 26, 2025
fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
matrixorigin#22570)

Align the default field separators for the export table and load data.

Approved by: @aunjgr, @iamlinjunhong, @heni02

This branch was previously deployed

1 inactive deployment
ci — f8558670 Deployed Sep 26, 2025 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 Review effort 2/5 size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants