diff options
author | James Cohan <james.cohan@10gen.com> | 2015-07-16 12:12:36 -0400 |
---|---|---|
committer | James Cohan <james.cohan@10gen.com> | 2015-08-11 17:08:41 -0400 |
commit | f9828f5a0312801fa5b8592b31648a64f0ea7f67 (patch) | |
tree | 94f5f8236dca8e2bd5fcaa95615024f5b36efd96 /src/mongo/db/pipeline/accumulator_min_max.cpp | |
parent | ac4450e7e2102705a8667ac43540689b998b9b60 (diff) | |
download | mongo-f9828f5a0312801fa5b8592b31648a64f0ea7f67.tar.gz |
SERVER-9625 Makes $sum, $avg, $min, $max, $stdDevPop, and $stdDevSamp accumulators available as expressions
Diffstat (limited to 'src/mongo/db/pipeline/accumulator_min_max.cpp')
-rw-r--r-- | src/mongo/db/pipeline/accumulator_min_max.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/mongo/db/pipeline/accumulator_min_max.cpp b/src/mongo/db/pipeline/accumulator_min_max.cpp index 9bfbf7b380b..fc854ca1ddb 100644 --- a/src/mongo/db/pipeline/accumulator_min_max.cpp +++ b/src/mongo/db/pipeline/accumulator_min_max.cpp @@ -29,14 +29,17 @@ #include "mongo/platform/basic.h" #include "mongo/db/pipeline/accumulator.h" +#include "mongo/db/pipeline/expression.h" #include "mongo/db/pipeline/value.h" namespace mongo { using boost::intrusive_ptr; -REGISTER_ACCUMULATOR(max, AccumulatorMinMax::createMax); -REGISTER_ACCUMULATOR(min, AccumulatorMinMax::createMin); +REGISTER_ACCUMULATOR(max, AccumulatorMax::create); +REGISTER_ACCUMULATOR(min, AccumulatorMin::create); +REGISTER_EXPRESSION(max, ExpressionFromAccumulator<AccumulatorMax>::parse); +REGISTER_EXPRESSION(min, ExpressionFromAccumulator<AccumulatorMin>::parse); const char* AccumulatorMinMax::getOpName() const { if (_sense == 1) @@ -57,6 +60,9 @@ void AccumulatorMinMax::processInternal(const Value& input, bool merging) { } Value AccumulatorMinMax::getValue(bool toBeMerged) const { + if (_val.missing()) { + return Value(BSONNULL); + } return _val; } @@ -69,11 +75,11 @@ void AccumulatorMinMax::reset() { _memUsageBytes = sizeof(*this); } -intrusive_ptr<Accumulator> AccumulatorMinMax::createMin() { - return new AccumulatorMinMax(Sense::MIN); +intrusive_ptr<Accumulator> AccumulatorMin::create() { + return new AccumulatorMin(); } -intrusive_ptr<Accumulator> AccumulatorMinMax::createMax() { - return new AccumulatorMinMax(Sense::MAX); +intrusive_ptr<Accumulator> AccumulatorMax::create() { + return new AccumulatorMax(); } } |