Skip to content

Commit

Permalink
cherry pick pingcap#36500 to release-5.3
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
zyguan authored and ti-srebot committed Jul 28, 2022
1 parent d674b64 commit 0417611
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2106,7 +2106,29 @@ func (s *testSuite4) TestIssue18681(c *C) {
c.Assert(sc.WarningCount(), Equals, uint16(0))
}

<<<<<<< HEAD
func (s *testSuite4) TestLoadData(c *C) {
=======
func TestIssue33298(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
ctx := tk.Session().(sessionctx.Context)
defer ctx.SetValue(executor.LoadDataVarKey, nil)

tk.MustExec("use test")
tk.MustExec("drop table if exists load_data_test")
tk.MustExec("create table load_data_test (a varchar(10), b varchar(10))")

// According to https://dev.mysql.com/doc/refman/8.0/en/load-data.html , fixed-row format should be used when fields
// terminated by '' and enclosed by ''. However, tidb doesn't support it yet and empty terminator leads to infinite
// loop in `indexOfTerminator` (see https://github.com/pingcap/tidb/issues/33298).
require.Error(t, tk.ExecToErr("load data local infile '/tmp/nonexistence.csv' into table load_data_test fields terminated by ''"))
require.Error(t, tk.ExecToErr("load data local infile '/tmp/nonexistence.csv' into table load_data_test fields terminated by '' enclosed by ''"))
}

func TestLoadData(t *testing.T) {
>>>>>>> bce690170... planner: forbid load data with empty field terminator (#36500)
trivialMsg := "Records: 1 Deleted: 0 Skipped: 0 Warnings: 0"
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
4 changes: 4 additions & 0 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3476,6 +3476,10 @@ func (b *PlanBuilder) buildSelectPlanOfInsert(ctx context.Context, insert *ast.I
}

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

0 comments on commit 0417611

Please sign in to comment.