MCPcopy Create free account
hub / github.com/brimdata/super / pullupExpr

Function pullupExpr

compiler/optimizer/optimizer.go:545–579  ·  view source on GitHub ↗
(alias string, expr dag.Expr)

Source from the content-addressed store, hash-verified

543}
544
545func pullupExpr(alias string, expr dag.Expr) (dag.Expr, bool) {
546 e, ok := expr.(*dag.BinaryExpr)
547 if !ok {
548 return nil, false
549 }
550 if e.Op == "and" {
551 lhs, lok := pullupExpr(alias, e.LHS)
552 rhs, rok := pullupExpr(alias, e.RHS)
553 if !lok || !rok {
554 return nil, false
555 }
556 return dag.NewBinaryExpr("and", lhs, rhs), true
557 }
558 if e.Op == "or" {
559 lhs, lok := pullupExpr(alias, e.LHS)
560 rhs, rok := pullupExpr(alias, e.RHS)
561 if !lok || !rok {
562 return nil, false
563 }
564 return dag.NewBinaryExpr("or", lhs, rhs), true
565
566 }
567 var c dag.Expr
568 var this *dag.ThisExpr
569 if t, ok := e.LHS.(*dag.ThisExpr); ok && isConst(e.RHS) {
570 this, c = t, e.RHS
571 } else if t, ok := e.RHS.(*dag.ThisExpr); ok && isConst(e.LHS) {
572 this, c = t, e.LHS
573 }
574 if c == nil || this == nil || len(this.Path) < 1 || this.Path[0] != alias {
575 return nil, false
576 }
577 path := slices.Clone(this.Path[1:])
578 return dag.NewBinaryExpr(e.Op, dag.NewThis(path), c), true
579}
580
581func isConst(e dag.Expr) bool {
582 switch e := e.(type) {

Callers 1

joinFilterPullupFunction · 0.85

Calls 4

NewBinaryExprFunction · 0.92
NewThisFunction · 0.92
isConstFunction · 0.85
CloneMethod · 0.65

Tested by

no test coverage detected