Skip to content

Commit

Permalink
feat: fix the parser to allow multiple strings one after the other
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 committed Jan 30, 2024
1 parent 38573f0 commit cd120eb
Show file tree
Hide file tree
Showing 5 changed files with 9,799 additions and 9,698 deletions.
17 changes: 17 additions & 0 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2551,6 +2551,23 @@ func IsLiteral(expr Expr) bool {
}
}

// AppendString appends a string to the expression provided.
// This is intended to be used in the parser only for concatenating multiple strings together.
func AppendString(expr Expr, in string) Expr {
switch node := expr.(type) {
case *Literal:
node.Val = node.Val + in
return node
case *UnaryExpr:
node.Expr = AppendString(node.Expr, in)
return node
case *IntroducerExpr:
node.Expr = AppendString(node.Expr, in)
return node
}
return nil
}

func (ct *ColumnType) Invisible() bool {
return ct.Options.Invisible != nil && *ct.Options.Invisible
}
Expand Down
15 changes: 15 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3679,6 +3679,21 @@ var (
}, {
input: `select * from t1 where col1 like 'ks\_' and col2 = 'ks\_' and col1 like 'ks_' and col2 = 'ks_'`,
output: `select * from t1 where col1 like 'ks\_' and col2 = 'ks\_' and col1 like 'ks_' and col2 = 'ks_'`,
}, {
input: "select 1 from dual where 'bac' = 'b' 'a' 'c'",
output: "select 1 from dual where 'bac' = 'bac'",
}, {
input: "select 'b' 'a' 'c'",
output: "select 'bac' from dual",
}, {
input: "select 1 where 'bac' = N'b' 'a' 'c'",
output: "select 1 from dual where 'bac' = N'bac'",
/*We need to ignore this test because, after the normalizer, we change the produced NChar
string into an introducer expression, so the vttablet will never see a NChar string */
ignoreNormalizerTest: true,
}, {
input: "select _ascii 'b' 'a' 'c'",
output: "select _ascii 'bac' from dual",
}, {
input: `kill connection 18446744073709551615`,
}, {
Expand Down
Loading

0 comments on commit cd120eb

Please sign in to comment.