summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/accumulator.h
diff options
context:
space:
mode:
authorTed Tuckman <ted.tuckman@mongodb.com>2021-03-31 20:01:02 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-03-31 20:44:24 +0000
commitead95fd4d389d1e370798cfd9ba098ac27dafd2c (patch)
tree5ea483ec9e7cbc35be0ce58791fec3965d548792 /src/mongo/db/pipeline/accumulator.h
parentfef36dd6aa1ca9af511996511dfe757b3d8167fc (diff)
downloadmongo-ead95fd4d389d1e370798cfd9ba098ac27dafd2c.tar.gz
SERVER-54336 Implement expMovingAvg window function
Diffstat (limited to 'src/mongo/db/pipeline/accumulator.h')
-rw-r--r--src/mongo/db/pipeline/accumulator.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/accumulator.h b/src/mongo/db/pipeline/accumulator.h
index 5107445ed25..71f2dcb7f5a 100644
--- a/src/mongo/db/pipeline/accumulator.h
+++ b/src/mongo/db/pipeline/accumulator.h
@@ -473,4 +473,23 @@ private:
MutableDocument _output;
};
+class AccumulatorExpMovingAvg : public AccumulatorState {
+public:
+ AccumulatorExpMovingAvg(ExpressionContext* const expCtx, Decimal128 alpha);
+
+ void processInternal(const Value& input, bool merging) final;
+ Value getValue(bool toBeMerged) final;
+ const char* getOpName() const final;
+ void reset() final;
+
+ static boost::intrusive_ptr<AccumulatorState> create(ExpressionContext* const expCtx,
+ Decimal128 alpha);
+
+private:
+ Decimal128 _alpha;
+ Decimal128 _currentResult;
+ bool _init = false;
+ bool _isDecimal = false;
+};
+
} // namespace mongo