Skip to content

Commit

Permalink
[parser] parser: ast/expressions.go: IsNullExpr (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovewin99 authored and ti-chi-bot committed Oct 9, 2021
1 parent 7c7fca6 commit 46040af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion parser/ast/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ type IsNullExpr struct {

// Restore implements Recoverable interface.
func (n *IsNullExpr) Restore(sb *strings.Builder) error {
return errors.New("Not implemented")
n.Format(sb)
return nil
}

// Format the ExprNode into a Writer.
Expand Down
8 changes: 8 additions & 0 deletions parser/ast/expressions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,19 @@ func (tc *testExpressionsSuite) createTestCase4ColumnNameExpr() []exprTestCase {
}
}

func (tc *testExpressionsSuite) createTestCase4IsNullExpr() []exprTestCase {
return []exprTestCase{
{"select a is null", "SELECT `a` IS NULL"},
{"select a is not null", "SELECT `a` IS NOT NULL"},
}
}

func (tc *testExpressionsSuite) TestExpresionsRestore(c *C) {
parser := parser.New()
var testNodes []exprTestCase
testNodes = append(testNodes, tc.createTestCase4UnaryOperationExpr()...)
testNodes = append(testNodes, tc.createTestCase4ColumnNameExpr()...)
testNodes = append(testNodes, tc.createTestCase4IsNullExpr()...)

for _, node := range testNodes {
stmt, err := parser.ParseOneStmt(node.sourceSQL, "", "")
Expand Down

0 comments on commit 46040af

Please sign in to comment.