Skip to content

Commit

Permalink
[parser] parser: implement Restore for ValuesExpr (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
exialin authored and ti-chi-bot committed Oct 9, 2021
1 parent 20ff6cc commit 958c8ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion parser/ast/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,14 @@ type ValuesExpr struct {

// Restore implements Node interface.
func (n *ValuesExpr) Restore(ctx *RestoreCtx) error {
return errors.New("Not implemented")
ctx.WriteKeyWord("VALUES")
ctx.WritePlain("(")
if err := n.Column.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore ValuesExpr.Column")
}
ctx.WritePlain(")")

return nil
}

// Format the ExprNode into a Writer.
Expand Down
11 changes: 11 additions & 0 deletions parser/ast/expressions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,14 @@ func (tc *testExpressionsSuite) TestPatternLikeExprRestore(c *C) {
}
RunNodeRestoreTest(c, testCases, "select %s", extractNodeFunc)
}

func (tc *testExpressionsSuite) TestValuesExpr(c *C) {
testCases := []NodeRestoreTestCase{
{"values(a)", "VALUES(`a`)"},
{"values(a)+values(b)", "VALUES(`a`)+VALUES(`b`)"},
}
extractNodeFunc := func(node Node) Node {
return node.(*InsertStmt).OnDuplicate[0].Expr
}
RunNodeRestoreTest(c, testCases, "insert into t values (1,2,3) on duplicate key update c=%s", extractNodeFunc)
}

0 comments on commit 958c8ed

Please sign in to comment.