[parser] parser: implement Restore for ExistsSubqueryExpr (#126)

This commit is contained in:
LiMingji
2019-01-17 17:37:23 +08:00
committed by Ti Chi Robot
parent 7680e0a912
commit 08b3170dd6
2 changed files with 21 additions and 1 deletions

View File

@ -588,7 +588,15 @@ type ExistsSubqueryExpr struct {
// Restore implements Node interface.
func (n *ExistsSubqueryExpr) Restore(ctx *RestoreCtx) error {
return errors.New("Not implemented")
if n.Not {
ctx.WriteKeyWord("NOT EXISTS ")
} else {
ctx.WriteKeyWord("EXISTS ")
}
if err := n.Sel.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore ExistsSubqueryExpr.Sel")
}
return nil
}
// Format the ExprNode into a Writer.

View File

@ -324,6 +324,18 @@ func (tc *testExpressionsSuite) TestPositionExprRestore(c *C) {
return node.(*SelectStmt).OrderBy.Items[0]
}
RunNodeRestoreTest(c, testCases, "select * from t order by %s", extractNodeFunc)
}
func (tc *testExpressionsSuite) TestExistsSubqueryExprRestore(c *C) {
testCases := []NodeRestoreTestCase{
{"EXISTS (SELECT 2)", "EXISTS (SELECT 2)"},
{"NOT EXISTS (SELECT 2)", "NOT EXISTS (SELECT 2)"},
}
extractNodeFunc := func(node Node) Node {
return node.(*SelectStmt).Where
}
RunNodeRestoreTest(c, testCases, "select 1 from t1 where %s", extractNodeFunc)
}
func (tc *testExpressionsSuite) TestVariableExpr(c *C) {