Skip to content

Commit

Permalink
merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
James Cor committed Jul 10, 2023
2 parents 96093ab + 241b093 commit 7519189
Show file tree
Hide file tree
Showing 5 changed files with 7,908 additions and 7,879 deletions.
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
48 changes: 29 additions & 19 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 @@ -432,12 +440,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 @@ -455,12 +457,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 @@ -3386,6 +3382,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)
}
}
}

func TestGeneratedColumns(t *testing.T) {
tests := []parseTest{
{
Expand Down Expand Up @@ -4022,6 +4027,9 @@ func TestInvalid(t *testing.T) {
}{{
input: "SET @foo = `o` `ne`;",
err: "syntax error",
}, {
input: "select '1' '2",
err: "syntax error",
}, {
input: "CHANGE REPLICATION FILTER",
err: "syntax error",
Expand Down Expand Up @@ -4091,13 +4099,15 @@ func TestInvalid(t *testing.T) {
}

for _, tcase := range invalidSQL {
_, err := Parse(tcase.input)
if err == nil {
t.Errorf("Parse invalid query(%q), got: nil, want: %s...", tcase.input, tcase.err)
}
if err != nil && !strings.Contains(err.Error(), tcase.err) {
t.Errorf("Parse invalid query(%q), got: %v, want: %s...", tcase.input, err, tcase.err)
}
t.Run(tcase.input, func(t *testing.T) {
_, err := Parse(tcase.input)
if err == nil {
t.Errorf("Parse invalid query(%q), got: nil, want: %s...", tcase.input, tcase.err)
}
if err != nil && !strings.Contains(err.Error(), tcase.err) {
t.Errorf("Parse invalid query(%q), got: %v, want: %s...", tcase.input, err, tcase.err)
}
})
}

invalidDDL := []struct {
Expand Down
Loading

0 comments on commit 7519189

Please sign in to comment.