Skip to content

Commit 5263a0a

Browse files
authored
planner: forbid load data with empty field terminator (#36500) (#36686)
close #33298
1 parent a5fd7d1 commit 5263a0a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

executor/write_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,24 @@ func TestIssue34358(t *testing.T) {
19951995
}, ld, t, tk, ctx, "select * from load_data_test", "delete from load_data_test")
19961996
}
19971997

1998+
func TestIssue33298(t *testing.T) {
1999+
store, clean := testkit.CreateMockStore(t)
2000+
defer clean()
2001+
tk := testkit.NewTestKit(t, store)
2002+
ctx := tk.Session().(sessionctx.Context)
2003+
defer ctx.SetValue(executor.LoadDataVarKey, nil)
2004+
2005+
tk.MustExec("use test")
2006+
tk.MustExec("drop table if exists load_data_test")
2007+
tk.MustExec("create table load_data_test (a varchar(10), b varchar(10))")
2008+
2009+
// According to https://dev.mysql.com/doc/refman/8.0/en/load-data.html , fixed-row format should be used when fields
2010+
// terminated by '' and enclosed by ''. However, tidb doesn't support it yet and empty terminator leads to infinite
2011+
// loop in `indexOfTerminator` (see https://github.com/pingcap/tidb/issues/33298).
2012+
require.Error(t, tk.ExecToErr("load data local infile '/tmp/nonexistence.csv' into table load_data_test fields terminated by ''"))
2013+
require.Error(t, tk.ExecToErr("load data local infile '/tmp/nonexistence.csv' into table load_data_test fields terminated by '' enclosed by ''"))
2014+
}
2015+
19982016
func TestLoadData(t *testing.T) {
19992017
trivialMsg := "Records: 1 Deleted: 0 Skipped: 0 Warnings: 0"
20002018
store, clean := testkit.CreateMockStore(t)

planner/core/planbuilder.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3891,6 +3891,10 @@ func (b *PlanBuilder) buildSelectPlanOfInsert(ctx context.Context, insert *ast.I
38913891
}
38923892

38933893
func (b *PlanBuilder) buildLoadData(ctx context.Context, ld *ast.LoadDataStmt) (Plan, error) {
3894+
// quick fix for https://github.com/pingcap/tidb/issues/33298
3895+
if ld.FieldsInfo != nil && len(ld.FieldsInfo.Terminated) == 0 {
3896+
return nil, ErrNotSupportedYet.GenWithStackByArgs("load data with empty field terminator")
3897+
}
38943898
p := LoadData{
38953899
IsLocal: ld.IsLocal,
38963900
OnDuplicate: ld.OnDuplicate,

0 commit comments

Comments
 (0)