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

parser: implement Restore for OnCondition and TableRefsClause #132

Merged
merged 3 commits into from
Dec 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ func (n *Join) Restore(ctx *RestoreCtx) error {
ctx.JoinLevel--

if n.On != nil {
ctx.WriteKeyWord(" ON ")
if err := n.On.Expr.Restore(ctx); err != nil {
ctx.WritePlain(" ")
if err := n.On.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore Join.On")
}
}
Expand Down Expand Up @@ -325,7 +325,11 @@ type OnCondition struct {

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

// Accept implements Node Accept interface.
Expand Down
11 changes: 11 additions & 0 deletions ast/dml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ func (tc *testDMLSuite) TestTableSourceRestore(c *C) {
RunNodeRestoreTest(c, testCases, "select * from %s", extractNodeFunc)
}

func (tc *testDMLSuite) TestOnConditionRestore(c *C) {
testCases := []NodeRestoreTestCase{
{"on t1.a=t2.a", "ON `t1`.`a`=`t2`.`a`"},
{"on t1.a=t2.a and t1.b=t2.b", "ON `t1`.`a`=`t2`.`a`&&`t1`.`b`=`t2`.`b`"},
}
extractNodeFunc := func(node Node) Node {
return node.(*SelectStmt).From.TableRefs.On
}
RunNodeRestoreTest(c, testCases, "select * from t1 join t2 %s", extractNodeFunc)
}

func (tc *testDMLSuite) TestJoinRestore(c *C) {
testCases := []NodeRestoreTestCase{
{"t1 natural join t2", "`t1` NATURAL JOIN `t2`"},
Expand Down