Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions enginetest/queries/load_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ import (
)

var LoadDataScripts = []ScriptTest{
{
Name: "LOAD DATA applies column defaults when \\N provided",
SetUpScript: []string{
"create table t (pk int primary key, c1 int default 1, c2 int)",
// Explicitly use Windows-style line endings to be robust on Windows CI
"LOAD DATA INFILE './testdata/load_defaults_null.csv' INTO TABLE t FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'",
},
Assertions: []ScriptTestAssertion{
{
Query: "select * from t",
Expected: []sql.Row{{1, 1, 1}},
},
},
},
{
Name: "Basic load data with enclosed values.",
SetUpScript: []string{
Expand Down
1 change: 1 addition & 0 deletions enginetest/testdata/load_defaults_null.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1,\N,1
14 changes: 13 additions & 1 deletion sql/rowexec/ddl_iters.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,19 @@ func (l *loadDataIter) parseFields(ctx *sql.Context, line string) ([]sql.Express
}
}
case "NULL":
exprs[exprIdx] = expression.NewLiteral(nil, types.Null)
// For MySQL LOAD DATA semantics, \N (mapped to NULL here) should use the column default
// if one exists; otherwise insert NULL.
destIdx := l.fieldToColMap[fieldIdx]
if destIdx >= 0 {
destCol := l.destSch[destIdx]
if destCol.Default != nil {
exprs[exprIdx] = destCol.Default
} else {
exprs[exprIdx] = expression.NewLiteral(nil, types.Null)
}
} else {
exprs[exprIdx] = expression.NewLiteral(nil, types.Null)
}
default:
exprs[exprIdx] = expression.NewLiteral(field, types.LongText)
}
Expand Down
Loading