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

parser: support to character option to load data statement #7391

Merged
merged 6 commits into from Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions parser/parser.y
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the last space.

{
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
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