diff --git a/parser/ast/expressions.go b/parser/ast/expressions.go index 47e9a1d581fe1..04fad58f247cd 100644 --- a/parser/ast/expressions.go +++ b/parser/ast/expressions.go @@ -715,7 +715,20 @@ type IsTruthExpr struct { // Restore implements Node interface. func (n *IsTruthExpr) Restore(ctx *RestoreCtx) error { - return errors.New("Not implemented") + if err := n.Expr.Restore(ctx); err != nil { + return errors.Trace(err) + } + if n.Not { + ctx.WriteKeyWord(" IS NOT") + } else { + ctx.WriteKeyWord(" IS") + } + if n.True > 0 { + ctx.WriteKeyWord(" TRUE") + } else { + ctx.WriteKeyWord(" FALSE") + } + return nil } // Format the ExprNode into a Writer. diff --git a/parser/ast/expressions_test.go b/parser/ast/expressions_test.go index 582a89b6a04d2..5e6675fe62b6d 100644 --- a/parser/ast/expressions_test.go +++ b/parser/ast/expressions_test.go @@ -142,6 +142,19 @@ func (tc *testExpressionsSuite) TestIsNullExprRestore(c *C) { RunNodeRestoreTest(c, testCases, "select %s", extractNodeFunc) } +func (tc *testExpressionsSuite) TestIsTruthRestore(c *C) { + testCases := []NodeRestoreTestCase{ + {"a is true", "`a` IS TRUE"}, + {"a is not true", "`a` IS NOT TRUE"}, + {"a is FALSE", "`a` IS FALSE"}, + {"a is not false", "`a` IS NOT FALSE"}, + } + extractNodeFunc := func(node Node) Node { + return node.(*SelectStmt).Fields.Fields[0].Expr + } + RunNodeRestoreTest(c, testCases, "select %s", extractNodeFunc) +} + func (tc *testExpressionsSuite) TestBetweenExprRestore(c *C) { testCases := []NodeRestoreTestCase{ {"b between 1 and 2", "`b` BETWEEN 1 AND 2"},