Skip to content

Commit

Permalink
feat: fix parsing for values
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <manan@planetscale.com>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
  • Loading branch information
GuptaManan100 authored and harshit-gangal committed Jan 9, 2025
1 parent e9b7d2d commit c46af56
Show file tree
Hide file tree
Showing 13 changed files with 10,185 additions and 10,078 deletions.
1 change: 1 addition & 0 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -3581,6 +3581,7 @@ type Values []ValTuple

// ValuesStatement represents a VALUES statement, as in VALUES ROW(1, 2), ROW(3, 4)
type ValuesStatement struct {
With *With
// One but not both of these fields can be set.
Rows Values
ListArg ListArg
Expand Down
1 change: 1 addition & 0 deletions go/vt/sqlparser/ast_clone.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion go/vt/sqlparser/ast_copy_on_rewrite.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion go/vt/sqlparser/ast_equals.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions go/vt/sqlparser/ast_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ func (node *VStream) Format(buf *TrackedBuffer) {

// Format formats the node.
func (node *ValuesStatement) Format(buf *TrackedBuffer) {
if node.With != nil {
buf.astPrintf(node, "%v", node.With)
}
buf.WriteString("values ")
if node.ListArg != "" {
buf.astPrintf(node, "%v", node.ListArg)
Expand Down
3 changes: 3 additions & 0 deletions go/vt/sqlparser/ast_format_fast.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2999,7 +2999,7 @@ func (node *ValuesStatement) SetInto(into *SelectInto) {
}

func (node *ValuesStatement) SetWith(with *With) {
panic("cannot set With on Values statement")
node.With = with
}

func (node *ValuesStatement) MakeDistinct() {
Expand Down
5 changes: 5 additions & 0 deletions go/vt/sqlparser/ast_rewrite.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions go/vt/sqlparser/ast_visit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions go/vt/sqlparser/cached_size.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3868,7 +3868,20 @@ var (
}, {
input: `select * from tbl where foo > any (select foo from tbl2)`,
}, {
input: `select * from tbl where foo > all (select foo from tbl2)`}}
input: `select * from tbl where foo > all (select foo from tbl2)`,
}, {
input: "insert into t1(a1) values row('a'), row('b')",
}, {
input: "insert into t1(a1) values ('a'), ('b')",
}, {
input: "values row('a'), row('b')",
}, {
input: `with x as (select * from t1 limit 1) values ROW('a1', (select x.a1 from x))`,
output: "with x as (select * from t1 limit 1) values row('a1', (select x.a1 from x))",
}, {
input: "SELECT 1,2 UNION SELECT * from (VALUES ROW(10,15)) t",
output: "select 1, 2 from dual union select * from (values row(10, 15)) as t",
}}
)

func TestValid(t *testing.T) {
Expand Down Expand Up @@ -6204,6 +6217,12 @@ var (
}, {
input: "create database test_db default encryption @a",
output: "syntax error at position 46 near 'a'",
}, {
input: "select * from t1 where a1 in row('a')",
output: "syntax error at position 33 near 'row'",
}, {
input: "insert into t1 (a1) values row('a'), ('b')",
output: "syntax error at position 39",
}}
)

Expand Down
Loading

0 comments on commit c46af56

Please sign in to comment.