[parser] parser: implement Restore for ExistsSubqueryExpr (#126)
This commit is contained in:
@ -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.
|
||||
|
||||
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user