Skip to content

Commit d9d8773

Browse files
committed
Count operator
This commit adds the count operator an operator that outputs the current count of values into a record expression.
1 parent 4493acd commit d9d8773

File tree

19 files changed

+3876
-3495
lines changed

19 files changed

+3876
-3495
lines changed

compiler/ast/op.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ type (
6060
Args []Expr `json:"args"`
6161
Loc `json:"loc"`
6262
}
63+
CountOp struct {
64+
Kind string `json:"kind" unpack:""`
65+
Expr Expr `json:"expr"`
66+
Loc `json:"loc"`
67+
}
6368
CutOp struct {
6469
Kind string `json:"kind" unpack:""`
6570
Args Assignments `json:"args"`
@@ -348,6 +353,7 @@ func (*AggregateOp) opNode() {}
348353
func (*AssertOp) opNode() {}
349354
func (*AssignmentOp) opNode() {}
350355
func (*CallOp) opNode() {}
356+
func (*CountOp) opNode() {}
351357
func (*CutOp) opNode() {}
352358
func (*DebugOp) opNode() {}
353359
func (*Delete) opNode() {}

compiler/dag/op.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ type (
6363
CombineOp struct {
6464
Kind string `json:"kind" unpack:""`
6565
}
66+
CountOp struct {
67+
Kind string `json:"kind" unpack:""`
68+
Alias string `json:"alias"`
69+
Expr Expr `json:"expr"`
70+
}
6671
CutOp struct {
6772
Kind string `json:"kind" unpack:""`
6873
Args []Assignment `json:"args"`
@@ -205,6 +210,7 @@ type (
205210

206211
func (*AggregateOp) opNode() {}
207212
func (*CombineOp) opNode() {}
213+
func (*CountOp) opNode() {}
208214
func (*CutOp) opNode() {}
209215
func (*DistinctOp) opNode() {}
210216
func (*DropOp) opNode() {}

compiler/optimizer/demand.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ func demandForSimpleOp(op dag.Op, downstream demand.Demand) demand.Demand {
7272
return d
7373
case *dag.CombineOp:
7474
return downstream
75+
case *dag.CountOp:
76+
return demand.Union(downstream, demandForExpr(op.Expr))
7577
case *dag.CutOp:
7678
return demandForAssignments(op.Args, demand.None())
7779
case *dag.DistinctOp:

compiler/optimizer/parallelize.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ func (o *Optimizer) concurrentPath(seq dag.Seq, sortKeys order.SortKeys) (length
277277
return k, sortExprsForSortKeys(sortKeys), true, nil
278278
}
279279
return k, nil, false, nil
280+
case *dag.CountOp:
281+
return k, nil, true, nil
280282
case *dag.SortOp:
281283
if len(op.Exprs) == 0 {
282284
// No analysis for sort without expression since we can't

0 commit comments

Comments
 (0)