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

feat(mysql): Add parser support for IS [NOT] NULL #2651

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 10 additions & 5 deletions internal/compiler/output_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,17 @@ func (c *Compiler) outputColumns(qc *QueryCatalog, node ast.Node) ([]*Column, er
name = *res.Name
}
notNull := false
if n.Boolop == ast.BoolExprTypeNot && len(n.Args.Items) == 1 {
sublink, ok := n.Args.Items[0].(*ast.SubLink)
if ok && sublink.SubLinkType == ast.EXISTS_SUBLINK {
if len(n.Args.Items) == 1 {
switch n.Boolop {
case ast.BoolExprTypeIsNull, ast.BoolExprTypeIsNotNull:
notNull = true
if name == "" {
name = "not_exists"
case ast.BoolExprTypeNot:
sublink, ok := n.Args.Items[0].(*ast.SubLink)
if ok && sublink.SubLinkType == ast.EXISTS_SUBLINK {
notNull = true
if name == "" {
name = "not_exists"
}
}
}
}
Expand Down
54 changes: 54 additions & 0 deletions internal/endtoend/testdata/comparisons/mysql/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions internal/endtoend/testdata/comparisons/mysql/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ SELECT count(*) <> 0 FROM bar;
-- name: Equal :many
SELECT count(*) = 0 FROM bar;

-- name: IsNull :many
SELECT id IS NULL FROM bar;





-- name: IsNotNull :many
SELECT id IS NOT NULL FROM bar;
13 changes: 12 additions & 1 deletion internal/engine/dolphin/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,18 @@ func (c *cc) convertIndexPartSpecification(n *pcast.IndexPartSpecification) ast.
}

func (c *cc) convertIsNullExpr(n *pcast.IsNullExpr) ast.Node {
return todo(n)
op := ast.BoolExprTypeIsNull
if n.Not {
op = ast.BoolExprTypeIsNotNull
}
return &ast.BoolExpr{
Boolop: op,
Args: &ast.List{
Items: []ast.Node{
c.convert(n.Expr),
},
},
}
}

func (c *cc) convertIsTruthExpr(n *pcast.IsTruthExpr) ast.Node {
Expand Down
4 changes: 4 additions & 0 deletions internal/sql/ast/bool_expr_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const (
BoolExprTypeAnd
BoolExprTypeOr
BoolExprTypeNot

// Added for MySQL
BoolExprTypeIsNull
BoolExprTypeIsNotNull
)

type BoolExprType uint
Expand Down
Loading