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

Function mergeFilters

compiler/optimizer/optimizer.go:42–58  ·  view source on GitHub ↗

mergeFilters transforms the DAG by merging adjacent filter operators so that, e.g., "where a | where b" becomes "where a and b". Note: mergeFilters does not descend into dag.OverExpr.Scope, so it cannot merge filters in "over" expressions like "sum(over a | where b | where c)".

(seq dag.Seq)

Source from the content-addressed store, hash-verified

40// Note: mergeFilters does not descend into dag.OverExpr.Scope, so it cannot
41// merge filters in "over" expressions like "sum(over a | where b | where c)".
42func mergeFilters(seq dag.Seq) dag.Seq {
43 walkT(reflect.ValueOf(&seq), func(seq dag.Seq) dag.Seq {
44 // Start at the next to last element and work toward the first.
45 for i := len(seq) - 2; i >= 0; i-- {
46 if f1, ok := seq[i].(*dag.FilterOp); ok {
47 if f2, ok := seq[i+1].(*dag.FilterOp); ok {
48 // Merge the second filter into the
49 // first and then delete the second.
50 f1.Expr = dag.NewBinaryExpr("and", f1.Expr, f2.Expr)
51 seq.Delete(i+1, i+2)
52 }
53 }
54 }
55 return seq
56 })
57 return seq
58}
59
60func removePassOps(seq dag.Seq) dag.Seq {
61 return Walk(seq, func(seq dag.Seq) dag.Seq {

Callers 2

OptimizeMethod · 0.85
joinFilterPullupFunction · 0.85

Calls 3

NewBinaryExprFunction · 0.92
walkTFunction · 0.85
DeleteMethod · 0.65

Tested by

no test coverage detected