Skip to content
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
18 changes: 17 additions & 1 deletion compiler/optimizer/parallelize.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package optimizer

import (
"reflect"

"github.com/brimdata/super/compiler/dag"
"github.com/brimdata/super/order"
)
Expand Down Expand Up @@ -299,7 +301,12 @@ func (o *Optimizer) concurrentPath(seq dag.Seq, sortKeys order.SortKeys) (length
// upstream sort is the same as the Load destination sort we
// request a merge and set the Load operator to do a sorted write.
return k, nil, false, nil
case *dag.ForkOp, *dag.ScatterOp, *dag.HeadOp, *dag.TailOp, *dag.UniqOp, *dag.FuseOp,
case *dag.SwitchOp:
if hasAggregate(op) {
return 0, nil, false, nil
}
return k, sortExprsForSortKeys(sortKeys), true, nil
case *dag.ForkOp, *dag.HeadOp, *dag.ScatterOp, *dag.TailOp, *dag.UniqOp, *dag.FuseOp,
*dag.HashJoinOp, *dag.InferOp, *dag.JoinOp, *dag.OutputOp:
return k, sortExprsForSortKeys(sortKeys), true, nil
default:
Expand All @@ -316,6 +323,15 @@ func (o *Optimizer) concurrentPath(seq dag.Seq, sortKeys order.SortKeys) (length
return len(seq), sortExprsForSortKeys(sortKeys), true, nil
}

func hasAggregate(op dag.Op) bool {
var found bool
walkT(reflect.ValueOf(op), func(a *dag.AggregateOp) *dag.AggregateOp {
found = true
return a
})
return found
}

func sortExprsForSortKeys(keys order.SortKeys) []dag.SortExpr {
var exprs []dag.SortExpr
for _, k := range keys {
Expand Down
16 changes: 16 additions & 0 deletions compiler/ztests/par-switch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# A switch operator containing an aggregate operator cannot be parallelized.
script: |
super compile -vam -C -P 2 'from /dev/null | switch default ( aggregate count() ) | sort count'

outputs:
- name: stdout
data: |
file /dev/null unordered
| switch
case true (
aggregate
count:=count()
| values count
)
| sort count asc nulls last
| output main
Loading