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

Function liftFilterOps

compiler/optimizer/optimizer.go:606–652  ·  view source on GitHub ↗
(seq dag.Seq)

Source from the content-addressed store, hash-verified

604}
605
606func liftFilterOps(seq dag.Seq) dag.Seq {
607 walkT(reflect.ValueOf(&seq), func(seq dag.Seq) dag.Seq {
608 for i := len(seq) - 2; i >= 0; i-- {
609 y, ok := seq[i].(*dag.ValuesOp)
610 if !ok || len(y.Exprs) != 1 {
611 continue
612 }
613 re, ok1 := y.Exprs[0].(*dag.RecordExpr)
614 f, ok2 := seq[i+1].(*dag.FilterOp)
615 if !ok1 || !ok2 || hasThisWithEmptyPath(f) {
616 continue
617 }
618 fields, spread, ok := recordElemsFieldsAndSpread(re.Elems)
619 if !ok {
620 continue
621 }
622 f = dag.CopyOp(f).(*dag.FilterOp)
623 liftOK := true
624 walkT(reflect.ValueOf(f), func(e dag.Expr) dag.Expr {
625 if !liftOK {
626 return e
627 }
628 this, ok := e.(*dag.ThisExpr)
629 if !ok {
630 return e
631 }
632 e1, ok := fields[this.Path[0]]
633 if !ok {
634 if spread == nil {
635 return newErrorMissing()
636 }
637 // Copy spread so f and y don't share dag.Exprs.
638 e, liftOK = addPathToExpr(dag.CopyExpr(spread), this.Path)
639 return e
640 }
641 // Copy e1 so f and y don't share dag.Exprs.
642 e, liftOK = addPathToExpr(dag.CopyExpr(e1), this.Path[1:])
643 return e
644 })
645 if liftOK {
646 seq[i], seq[i+1] = f, y
647 }
648 }
649 return seq
650 })
651 return seq
652}
653
654func mergeValuesOps(seq dag.Seq) dag.Seq {
655 return Walk(seq, func(seq dag.Seq) dag.Seq {

Callers 1

OptimizeMethod · 0.85

Calls 7

CopyOpFunction · 0.92
CopyExprFunction · 0.92
walkTFunction · 0.85
hasThisWithEmptyPathFunction · 0.85
newErrorMissingFunction · 0.85
addPathToExprFunction · 0.85

Tested by

no test coverage detected