summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/accumulator_min_max.cpp
diff options
context:
space:
mode:
authorJames Cohan <james.cohan@10gen.com>2015-07-16 12:12:36 -0400
committerJames Cohan <james.cohan@10gen.com>2015-08-11 17:08:41 -0400
commitf9828f5a0312801fa5b8592b31648a64f0ea7f67 (patch)
tree94f5f8236dca8e2bd5fcaa95615024f5b36efd96 /src/mongo/db/pipeline/accumulator_min_max.cpp
parentac4450e7e2102705a8667ac43540689b998b9b60 (diff)
downloadmongo-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.cpp18
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();
}
}