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

Automatically concatenate adjacent string literals #253

Merged
merged 9 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func captureSelectExpressions(sql string, tokenizer *Tokenizer) {
// column names don't need any special handling to capture the input expression
return false, nil
} else {
node.InputExpression = trimQuotes(strings.TrimLeft(sql[node.StartParsePos:node.EndParsePos], " \n\t"))
node.InputExpression = trimQuotes(strings.Trim(sql[node.StartParsePos:node.EndParsePos], " \n\t"))
}
}
return true, nil
Expand Down
29 changes: 17 additions & 12 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ var (
input: "CREATE table t (pk int primary key, fk int REFERENCES parent(id))",
output: "create table t (\n\tpk int primary key,\n\tfk int references parent [id]\n)",
},
{
input: `Select 'a' "b" 'c'`,
output: "select 'abc'",
},
{
input: `Select concat('a' "b" 'c', "de" 'f')`,
output: "select concat('abc', 'def')",
},
{
input: "SET @foo = 'o' 'ne';",
output: "set @foo = 'one'",
Expand Down Expand Up @@ -412,12 +420,6 @@ var (
output: "select /* table alias */ 1 from t as t1",
}, {
input: "select /* table alias with as */ 1 from t as t1",
}, {
input: "select /* string table alias */ 1 from t as 't1'",
output: "select /* string table alias */ 1 from t as t1",
}, {
input: "select /* string table alias without as */ 1 from t 't1'",
output: "select /* string table alias without as */ 1 from t as t1",
}, {
input: "select /* keyword table alias */ 1 from t as `By`",
}, {
Expand All @@ -435,12 +437,6 @@ var (
output: "select /* table alias */ 1 from t as of '2019-01-01' as t1",
}, {
input: "select /* table alias with as */ 1 from t as of '2019-01-01' as t1",
}, {
input: "select /* string table alias */ 1 from t as of '2019-01-01' as 't1'",
output: "select /* string table alias */ 1 from t as of '2019-01-01' as t1",
}, {
input: "select /* string table alias without as */ 1 from t as of '2019-01-01' 't1'",
output: "select /* string table alias without as */ 1 from t as of '2019-01-01' as t1",
}, {
input: "select /* keyword table alias */ 1 from t as of '2019-01-01' as `By`",
}, {
Expand Down Expand Up @@ -3364,6 +3360,15 @@ func TestValid(t *testing.T) {
}
}

func TestSingle(t *testing.T) {
validSQL = append(validSQL, validMultiStatementSql...)
for _, tcase := range validSQL {
if tcase.input == "select \"'ain't'\", '\"hello\"' from t" {
runParseTestCase(t, tcase)
}
}
}
Comment on lines +3363 to +3370
Copy link

Choose a reason for hiding this comment

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

Did you mean to leave this in?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it's handy for testing


func TestGeneratedColumns(t *testing.T) {
tests := []parseTest{
{
Expand Down
Loading