Skip to content

Commit

Permalink
parser: support to character option to load data statement (#7391)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lingyu Song authored Aug 15, 2018
1 parent 016006f commit 4684eec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 10 additions & 6 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -6821,25 +6821,29 @@ RevokeStmt:
* See https://dev.mysql.com/doc/refman/5.7/en/load-data.html
*******************************************************************************************/
LoadDataStmt:
"LOAD" "DATA" LocalOpt "INFILE" stringLit "INTO" "TABLE" TableName Fields Lines ColumnNameListOptWithBrackets
"LOAD" "DATA" LocalOpt "INFILE" stringLit "INTO" "TABLE" TableName CharsetOpt Fields Lines ColumnNameListOptWithBrackets
{
x := &ast.LoadDataStmt{
Path: $5,
Table: $8.(*ast.TableName),
Columns: $11.([]*ast.ColumnName),
Columns: $12.([]*ast.ColumnName),
}
if $3 != nil {
x.IsLocal = true
}
if $9 != nil {
x.FieldsInfo = $9.(*ast.FieldsClause)
}
if $10 != nil {
x.LinesInfo = $10.(*ast.LinesClause)
x.FieldsInfo = $10.(*ast.FieldsClause)
}
if $11 != nil {
x.LinesInfo = $11.(*ast.LinesClause)
}
$$ = x
}

CharsetOpt:
{}
| "CHARACTER" "SET" CharsetName

LocalOpt:
{
$$ = nil
Expand Down
4 changes: 4 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ func (s *testParserSuite) TestDMLStmt(c *C) {

// load data
{"load data infile '/tmp/t.csv' into table t", true},
{"load data infile '/tmp/t.csv' into table t character set utf8", true},
{"load data infile '/tmp/t.csv' into table t fields terminated by 'ab'", true},
{"load data infile '/tmp/t.csv' into table t columns terminated by 'ab'", true},
{"load data infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b'", true},
Expand All @@ -371,6 +372,7 @@ func (s *testParserSuite) TestDMLStmt(c *C) {
{"load data local infile '/tmp/t.csv' into table t columns terminated by 'ab'", true},
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b'", true},
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b' escaped by '*'", true},
{"load data local infile '/tmp/t.csv' into table t character set utf8 fields terminated by 'ab' enclosed by 'b' escaped by '*'", true},
{"load data local infile '/tmp/t.csv' into table t lines starting by 'ab'", true},
{"load data local infile '/tmp/t.csv' into table t lines starting by 'ab' terminated by 'xy'", true},
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' lines terminated by 'xy'", true},
Expand All @@ -381,8 +383,10 @@ func (s *testParserSuite) TestDMLStmt(c *C) {
{"load data local infile '/tmp/t.csv' into table t columns terminated by 'ab' (a,b)", true},
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b' (a,b)", true},
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b' escaped by '*' (a,b)", true},
{"load data local infile '/tmp/t.csv' into table t character set utf8 fields terminated by 'ab' enclosed by 'b' escaped by '*' (a,b)", true},
{"load data local infile '/tmp/t.csv' into table t lines starting by 'ab' (a,b)", true},
{"load data local infile '/tmp/t.csv' into table t lines starting by 'ab' terminated by 'xy' (a,b)", true},
{"load data local infile '/tmp/t.csv' into table t character set utf8 fields terminated by 'ab' lines terminated by 'xy' (a,b)", true},
{"load data local infile '/tmp/t.csv' into table t fields terminated by 'ab' lines terminated by 'xy' (a,b)", true},
{"load data local infile '/tmp/t.csv' into table t (a,b) fields terminated by 'ab'", false},

Expand Down

0 comments on commit 4684eec

Please sign in to comment.