diff --git a/parser/parser.y b/parser/parser.y index 80b283c5a9a53..73bc66d76c556 100644 --- a/parser/parser.y +++ b/parser/parser.y @@ -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 diff --git a/parser/parser_test.go b/parser/parser_test.go index 6ec18688bf07d..b38e1e2de34b0 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -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}, @@ -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}, @@ -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},