Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support recursive operator calls for $sum aggregation accumulator #3116

Merged
merged 18 commits into from
Jul 31, 2023
Prev Previous commit
Next Next commit
wip
  • Loading branch information
noisersup committed Jul 27, 2023
commit dd70fc329c44f825d74d5d2d809931a1502390d1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
// sum represents $sum aggregation operator.
type sum struct {
expression *aggregations.Expression
operator *operators.Operator
operator operators.Operator
number any
}

Expand Down Expand Up @@ -62,7 +62,7 @@ func newSum(accumulation *types.Document) (Accumulator, error) {
return nil, opErr
}

accumulator.operator = &op
accumulator.operator = op

case float64:
accumulator.number = expr
Expand Down Expand Up @@ -108,6 +108,20 @@ func (s *sum) Accumulate(iter types.DocumentsIterator) (any, error) {
continue
}

if s.operator != nil {
v, err := s.operator.Process(doc)
if err != nil {
// TODO
return nil, err
}

switch v.(type) {
case float64, int32, int64:
numbers = append(numbers, v)
}

}

switch number := s.number.(type) {
case float64, int32, int64:
// For number types, the result is equivalent of iterator len*number,
Expand Down