Skip to content

Commit

Permalink
parser: support LOAD DATA ... IGNORE/REPLACE (#10336)
Browse files Browse the repository at this point in the history
  • Loading branch information
sundl123 authored and zz-jason committed May 22, 2019
1 parent 3439e6b commit 54899f6
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/ddltest/random.go
Expand Up @@ -33,7 +33,7 @@ func randomFloat() float64 {
func randomString(n int) string {
const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
var bytes = make([]byte, n)
for i, _ := range bytes {
for i := range bytes {
bytes[i] = alphanum[randomIntn(len(alphanum))]
}
return string(bytes)
Expand Down
1 change: 1 addition & 0 deletions executor/builder.go
Expand Up @@ -657,6 +657,7 @@ func (b *executorBuilder) buildLoadData(v *plannercore.LoadData) Executor {
loadDataExec := &LoadDataExec{
baseExecutor: newBaseExecutor(b.ctx, nil, v.ExplainID()),
IsLocal: v.IsLocal,
OnDuplicate: v.OnDuplicate,
loadDataInfo: &LoadDataInfo{
row: make([]types.Datum, len(insertVal.insertColumns)),
InsertValues: insertVal,
Expand Down
5 changes: 5 additions & 0 deletions executor/load_data.go
Expand Up @@ -35,6 +35,7 @@ type LoadDataExec struct {
baseExecutor

IsLocal bool
OnDuplicate ast.OnDuplicateKeyHandlingType
loadDataInfo *LoadDataInfo
}

Expand All @@ -58,6 +59,10 @@ func (e *LoadDataExec) Next(ctx context.Context, req *chunk.RecordBatch) error {
if !e.IsLocal {
return errors.New("Load Data: don't support load data without local field")
}
// TODO: support load data with replace field.
if e.OnDuplicate == ast.OnDuplicateKeyHandlingReplace {
return errors.New("Load Data: don't support load data with replace field")
}
// TODO: support lines terminated is "".
if len(e.loadDataInfo.LinesInfo.Terminated) == 0 {
return errors.New("Load Data: don't support load data terminated is nil")
Expand Down
6 changes: 4 additions & 2 deletions executor/write_test.go
Expand Up @@ -1788,7 +1788,9 @@ func (s *testSuite4) TestLoadData(c *C) {
tk.MustExec(createSQL)
_, err = tk.Exec("load data infile '/tmp/nonexistence.csv' into table load_data_test")
c.Assert(err, NotNil)
tk.MustExec("load data local infile '/tmp/nonexistence.csv' into table load_data_test")
_, err = tk.Exec("load data local infile '/tmp/nonexistence.csv' replace into table load_data_test")
c.Assert(err, NotNil)
tk.MustExec("load data local infile '/tmp/nonexistence.csv' ignore into table load_data_test")
ctx := tk.Se.(sessionctx.Context)
ld, ok := ctx.Value(executor.LoadDataVarKey).(*executor.LoadDataInfo)
c.Assert(ok, IsTrue)
Expand Down Expand Up @@ -2018,7 +2020,7 @@ func (s *testSuite4) TestLoadDataIgnoreLines(c *C) {
checkCases(tests, ld, c, tk, ctx, selectSQL, deleteSQL)
}

// related to issue 6360
// TestLoadDataOverflowBigintUnsigned related to issue 6360
func (s *testSuite4) TestLoadDataOverflowBigintUnsigned(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test; drop table if exists load_data_test;")
Expand Down
1 change: 1 addition & 0 deletions planner/core/common_plans.go
Expand Up @@ -460,6 +460,7 @@ type LoadData struct {
baseSchemaProducer

IsLocal bool
OnDuplicate ast.OnDuplicateKeyHandlingType
Path string
Table *ast.TableName
Columns []*ast.ColumnName
Expand Down
1 change: 1 addition & 0 deletions planner/core/planbuilder.go
Expand Up @@ -1577,6 +1577,7 @@ func (b *PlanBuilder) buildSelectPlanOfInsert(insert *ast.InsertStmt, insertPlan
func (b *PlanBuilder) buildLoadData(ld *ast.LoadDataStmt) (Plan, error) {
p := &LoadData{
IsLocal: ld.IsLocal,
OnDuplicate: ld.OnDuplicate,
Path: ld.Path,
Table: ld.Table,
Columns: ld.Columns,
Expand Down

0 comments on commit 54899f6

Please sign in to comment.