Skip to content

Commit

Permalink
sam: Use SQL semantics for null comparison
Browse files Browse the repository at this point in the history
The commit changes the sequential runtime to embrace SQL semantics when
comparing values to nulls. This commit also changes the IS NULL
expression to not rely on generic equality compare which would produce
incorrect results with SQL null semantics.
  • Loading branch information
mattnibs committed Nov 19, 2024
1 parent 222ded6 commit 8c33d48
Show file tree
Hide file tree
Showing 19 changed files with 2,750 additions and 2,605 deletions.
8 changes: 8 additions & 0 deletions compiler/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ type IndexExpr struct {
Loc `json:"loc"`
}

type IsNullExpr struct {
Kind string `json:"kind" unpack:""`
Expr Expr `json:"expr"`
Not bool `json:"not"`
Loc `json:"loc"`
}

type SliceExpr struct {
Kind string `json:"kind" unpack:""`
Expr Expr `json:"expr"`
Expand Down Expand Up @@ -315,6 +322,7 @@ func (*CaseExpr) ExprAST() {}
func (*Cast) ExprAST() {}
func (*ID) ExprAST() {}
func (*IndexExpr) ExprAST() {}
func (*IsNullExpr) ExprAST() {}
func (*SliceExpr) ExprAST() {}

func (*Assignment) ExprAST() {}
Expand Down
1 change: 1 addition & 0 deletions compiler/ast/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var unpacker = unpack.New(
ID{},
ImpliedValue{},
IndexExpr{},
IsNullExpr{},
Join{},
Load{},
Merge{},
Expand Down
5 changes: 5 additions & 0 deletions compiler/dag/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ type (
Expr Expr `json:"expr"`
Index Expr `json:"index"`
}
IsNullExpr struct {
Kind string `json:"kind" unpack:""`
Expr Expr `json:"expr"`
}
Literal struct {
Kind string `json:"kind" unpack:""`
Value string `json:"value"`
Expand Down Expand Up @@ -148,6 +152,7 @@ func (*Conditional) ExprDAG() {}
func (*Dot) ExprDAG() {}
func (*Func) ExprDAG() {}
func (*IndexExpr) ExprDAG() {}
func (*IsNullExpr) ExprDAG() {}
func (*Literal) ExprDAG() {}
func (*MapCall) ExprDAG() {}
func (*MapExpr) ExprDAG() {}
Expand Down
1 change: 1 addition & 0 deletions compiler/dag/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var unpacker = unpack.New(
Head{},
HTTPScan{},
IndexExpr{},
IsNullExpr{},
Join{},
LakeMetaScan{},
Lister{},
Expand Down
10 changes: 10 additions & 0 deletions compiler/kernel/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func (b *Builder) compileExpr(e dag.Expr) (expr.Evaluator, error) {
return b.compileCall(*e)
case *dag.IndexExpr:
return b.compileIndexExpr(e)
case *dag.IsNullExpr:
return b.compileIsNullExpr(e)
case *dag.SliceExpr:
return b.compileSliceExpr(e)
case *dag.RegexpMatch:
Expand Down Expand Up @@ -405,6 +407,14 @@ func (b *Builder) compileIndexExpr(e *dag.IndexExpr) (expr.Evaluator, error) {
return expr.NewIndexExpr(b.zctx(), container, index), nil
}

func (b *Builder) compileIsNullExpr(e *dag.IsNullExpr) (expr.Evaluator, error) {
eval, err := b.compileExpr(e.Expr)
if err != nil {
return nil, err
}
return expr.NewIsNullExpr(eval), nil
}

func (b *Builder) compileRegexpMatch(match *dag.RegexpMatch) (expr.Evaluator, error) {
e, err := b.compileExpr(match.Expr)
if err != nil {
Expand Down
Loading

0 comments on commit 8c33d48

Please sign in to comment.