Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: forbid load data with empty field terminator #36500

Merged
merged 3 commits into from
Jul 28, 2022
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
18 changes: 18 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,24 @@ func TestIssue18681(t *testing.T) {
require.Equal(t, uint16(0), sc.WarningCount())
}

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) {
trivialMsg := "Records: 1 Deleted: 0 Skipped: 0 Warnings: 0"
store, clean := testkit.CreateMockStore(t)
Expand Down
4 changes: 4 additions & 0 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3913,6 +3913,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