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

Fix the parser to allow multiple strings one after the other #15076

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2151,7 +2151,7 @@
}

// RemoveKeyspaceInCol removes the Qualifier.Qualifier on all ColNames in the AST
func RemoveKeyspaceInCol(in SQLNode) {

Check warning on line 2154 in go/vt/sqlparser/ast_funcs.go

View check run for this annotation

Codecov / codecov/patch

go/vt/sqlparser/ast_funcs.go#L2154

Added line #L2154 was not covered by tests
// Walk will only return an error if we return an error from the inner func. safe to ignore here
_ = Walk(func(node SQLNode) (kontinue bool, err error) {
if col, ok := node.(*ColName); ok && col.Qualifier.Qualifier.NotEmpty() {
Expand All @@ -2176,20 +2176,20 @@
}

// RemoveKeyspace removes the Qualifier.Qualifier on all ColNames and Qualifier on all TableNames in the AST
func RemoveKeyspace(in SQLNode) {
Rewrite(in, nil, func(cursor *Cursor) bool {
switch expr := cursor.Node().(type) {
case *ColName:
if expr.Qualifier.Qualifier.NotEmpty() {
expr.Qualifier.Qualifier = NewIdentifierCS("")
}
case TableName:
if expr.Qualifier.NotEmpty() {
expr.Qualifier = NewIdentifierCS("")
cursor.Replace(expr)
}

Check warning on line 2190 in go/vt/sqlparser/ast_funcs.go

View check run for this annotation

Codecov / codecov/patch

go/vt/sqlparser/ast_funcs.go#L2179-L2190

Added lines #L2179 - L2190 were not covered by tests
}
return true

Check warning on line 2192 in go/vt/sqlparser/ast_funcs.go

View check run for this annotation

Codecov / codecov/patch

go/vt/sqlparser/ast_funcs.go#L2192

Added line #L2192 was not covered by tests
})
}

Expand Down Expand Up @@ -2551,6 +2551,23 @@
}
}

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

Check warning on line 2568 in go/vt/sqlparser/ast_funcs.go

View check run for this annotation

Codecov / codecov/patch

go/vt/sqlparser/ast_funcs.go#L2568

Added line #L2568 was not covered by tests
}

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
Loading