Skip to content

Commit c6c7daf

Browse files
committed
add line term in scanner split to detect eof when enc==esc edge case
1 parent b9b32d3 commit c6c7daf

16 files changed

+114
-57
lines changed

.gitattributes

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ enginetest/testdata/test8.txt binary
1010
enginetest/testdata/test9.txt binary
1111
enginetest/testdata/test10.txt binary
1212
enginetest/testdata/simple_json.txt binary
13-
enginetest/testdata/loaddata_9969.dat binary
14-
enginetest/testdata/loaddata_escape.dat binary
13+
enginetest/testdata/loaddata_null_in_field.dat binary
14+
enginetest/testdata/loaddata_lborder_null.dat binary
15+
enginetest/testdata/loaddata_enc_esc_eq.dat binary
16+
enginetest/testdata/loaddata_eof.dat binary
17+
enginetest/testdata/loaddata_term_in_field.dat binary
18+
enginetest/testdata/loaddata_mixed_escapes.dat binary
1519
enginetest/testdata/loaddata_enclosed.dat binary
1620
enginetest/testdata/loaddata_single_quotes.dat binary
1721
enginetest/testdata/loaddata_nulls.dat binary
18-
enginetest/testdata/loaddata_mixed_escapes.dat binary
22+
enginetest/testdata/loaddata_escape.dat binary

enginetest/queries/load_queries.go

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var LoadDataScripts = []ScriptTest{
2929
Name: "LOAD DATA with ENCLOSED BY and ESCAPED BY parsing",
3030
SetUpScript: []string{
3131
"create table t1(pk int primary key, c1 longtext)",
32-
"LOAD DATA INFILE './testdata/loaddata_9969.dat' INTO TABLE t1 FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ESCAPED BY '\"'",
32+
"LOAD DATA INFILE './testdata/loaddata_term_in_field.dat' INTO TABLE t1 FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ESCAPED BY '\"'",
3333
"create table t2(pk int primary key, c1 longtext)",
3434
"LOAD DATA INFILE './testdata/loaddata_escape.dat' INTO TABLE t2 FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ESCAPED BY '\\\\'",
3535
"create table t3(a varchar(20), b varchar(20))",
@@ -40,6 +40,14 @@ var LoadDataScripts = []ScriptTest{
4040
"LOAD DATA INFILE './testdata/loaddata_single_quotes.dat' INTO TABLE t5 FIELDS TERMINATED BY ',' ENCLOSED BY ''''",
4141
"create table t6(pk int, a varchar(20), b varchar(20))",
4242
"LOAD DATA INFILE './testdata/loaddata_nulls.dat' INTO TABLE t6 FIELDS TERMINATED BY ','",
43+
"create table t7(i int, v text)",
44+
"LOAD DATA INFILE './testdata/loaddata_eof.dat' INTO TABLE t7 FIELDS TERMINATED BY ',' ENCLOSED BY '$' ESCAPED BY '$'",
45+
"create table t8(i int, v text)",
46+
"LOAD DATA INFILE './testdata/loaddata_enc_esc_eq.dat' INTO TABLE t8 FIELDS TERMINATED BY ',' ENCLOSED BY '$' ESCAPED BY '$'",
47+
"create table t9(i int, v text)",
48+
"LOAD DATA INFILE './testdata/loaddata_lborder_null.dat' INTO TABLE t9 FIELDS TERMINATED BY ',' ENCLOSED BY '' ESCAPED BY ''",
49+
"create table t10(i int, v text)",
50+
"LOAD DATA INFILE './testdata/loaddata_null_in_field.dat' INTO TABLE t10 FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ESCAPED BY ''",
4351
},
4452
Assertions: []ScriptTestAssertion{
4553
{
@@ -67,7 +75,7 @@ var LoadDataScripts = []ScriptTest{
6775
},
6876
},
6977
{
70-
Query: "select * from t5", // order by a breaks
78+
Query: "select * from t5",
7179
Expected: []sql.Row{
7280
{"Field A", "Field B"},
7381
{"Field 1", "Field 2"},
@@ -84,10 +92,36 @@ var LoadDataScripts = []ScriptTest{
8492
{4, nil, nil},
8593
},
8694
},
95+
{
96+
Query: "select * from t7",
97+
Expected: []sql.Row{
98+
{1, "foo $0 $b $n $t $Z $N bar"},
99+
{2, "$foo $ bar$"},
100+
},
101+
},
102+
{
103+
Query: "select * from t8",
104+
Expected: []sql.Row{
105+
{1, "foo $0 $b $n $t $Z $N bar"},
106+
{2, "foo $ bar"},
107+
},
108+
},
109+
{
110+
Query: "select * from t9",
111+
Expected: []sql.Row{
112+
{1, "\x00foo bar"},
113+
},
114+
},
115+
{
116+
Query: "select * from t10",
117+
Expected: []sql.Row{
118+
{1, "foo \x00 bar"},
119+
},
120+
},
87121
},
88122
},
89123
{
90-
Name: "LOAD DATA applies column defaults when \\N provided",
124+
Name: "LOAD DATA does not apply column defaults when \\N provided",
91125
SetUpScript: []string{
92126
"create table t (pk int primary key, c1 int default 1, c2 int)",
93127
// Explicitly use Windows-style line endings to be robust on Windows CI
@@ -96,7 +130,7 @@ var LoadDataScripts = []ScriptTest{
96130
Assertions: []ScriptTestAssertion{
97131
{
98132
Query: "select * from t",
99-
Expected: []sql.Row{{1, 1, 1}},
133+
Expected: []sql.Row{{1, nil, 1}},
100134
},
101135
},
102136
},

enginetest/testdata/loaddata_9969.dat

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
$1$,$foo $0 $b $n $t $Z $N bar$
2+
$2$,$foo $$ bar$
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"field1","field2"
22
"a""b","cd""ef"
3-
"foo,bar","baz,qux"
3+
"foo,bar","baz,qux"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
$1$,$foo $0 $b $n $t $Z $N bar$
2+
$2$,$foo $$ bar$
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"1","foo\,bar"
1+
"1","foo\,bar"
10 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"hello\nworld","foo\tbar"
22
"a\,b","c\,d"
3-
"\N","\Z"
3+
"\N","\Z"
15 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)