Skip to content

Commit

Permalink
feat: add support for values statement with list argument bind variab…
Browse files Browse the repository at this point in the history
…le. Added new Row_Tuple bind variable type for formatting in vttablet

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
  • Loading branch information
harshit-gangal committed Sep 3, 2024
1 parent a9d27c9 commit 9fe7f3f
Show file tree
Hide file tree
Showing 19 changed files with 10,514 additions and 10,394 deletions.
11 changes: 9 additions & 2 deletions go/vt/proto/query/query.pb.go

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

22 changes: 8 additions & 14 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1703,9 +1703,10 @@ type InsertRows interface {
SQLNode
}

func (*Select) iInsertRows() {}
func (*Union) iInsertRows() {}
func (Values) iInsertRows() {}
func (*Select) iInsertRows() {}
func (*Union) iInsertRows() {}
func (Values) iInsertRows() {}
func (*ValuesStatement) iInsertRows() {}

// OptLike works for create table xxx like xxx
type OptLike struct {
Expand Down Expand Up @@ -3577,17 +3578,10 @@ type Limit struct {
type Values []ValTuple

type ValuesStatement struct {
Rows Values
Order OrderBy
Limit *Limit
}

func (s *ValuesStatement) AddOrder(order *Order) {
s.Order = append(s.Order, order)
}

func (s *ValuesStatement) SetLimit(limit *Limit) {
s.Limit = limit
Rows Values
ListArg ListArg
Order OrderBy
Limit *Limit
}

// UpdateExprs represents a list of update expressions.
Expand Down
4 changes: 4 additions & 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.

8 changes: 7 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.

13 changes: 13 additions & 0 deletions go/vt/sqlparser/ast_equals.go

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

12 changes: 8 additions & 4 deletions go/vt/sqlparser/ast_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,14 @@ func (node *VStream) Format(buf *TrackedBuffer) {
// Format formats the node.
func (node *ValuesStatement) Format(buf *TrackedBuffer) {
buf.WriteString("values ")
for i, row := range node.Rows {
buf.astPrintf(node, "row%v", row)
if i < len(node.Rows)-1 {
buf.WriteString(", ")
if node.ListArg != "" {
buf.astPrintf(node, "%v", node.ListArg)
} else {
for i, row := range node.Rows {
buf.astPrintf(node, "row%v", row)
if i < len(node.Rows)-1 {
buf.WriteString(", ")
}
}
}
buf.astPrintf(node, "%v%v",
Expand Down
14 changes: 9 additions & 5 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.

64 changes: 64 additions & 0 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2839,3 +2839,67 @@ func ExtractAllTables(stmt Statement) []string {
}, stmt)
return tables
}

var _ SelectStatement = (*ValuesStatement)(nil)

func (node *ValuesStatement) GetLock() Lock {
return NoLock
}

func (node *ValuesStatement) SetLock(lock Lock) {
if lock != NoLock {
panic("cannot set lock on Values statement")
}
}

func (node *ValuesStatement) SetInto(into *SelectInto) {
panic("cannot set Into on Values statement")
}

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

func (node *ValuesStatement) MakeDistinct() {
panic("cannot set Distinct on Values statement")
}

func (node *ValuesStatement) GetColumnCount() int {
panic("cannot call Column count on Values statement")
}

func (node *ValuesStatement) GetColumns() SelectExprs {
panic("cannot call Columns on Values statement")
}

func (node *ValuesStatement) SetComments(comments Comments) {
panic("cannot set Comments on Values statement")
}

func (node *ValuesStatement) GetParsedComments() *ParsedComments {
panic("cannot call Parsed comments on Values statement")
}

func (node *ValuesStatement) IsDistinct() bool {
return false
}

func (node *ValuesStatement) GetOrderBy() OrderBy {
return node.Order
}

func (node *ValuesStatement) SetOrderBy(by OrderBy) {
node.Order = by
}

func (node *ValuesStatement) GetLimit() *Limit {
return node.Limit
}

func (node *ValuesStatement) AddOrder(order *Order) {
node.Order = append(node.Order, order)
}

func (node *ValuesStatement) SetLimit(limit *Limit) {
node.Limit = limit
}
9 changes: 9 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.

7 changes: 7 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.

35 changes: 35 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.

Loading

0 comments on commit 9fe7f3f

Please sign in to comment.