summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrii Dobroshynski <andrii.dobroshynski@mongodb.com>2021-06-25 03:58:21 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-30 14:52:00 +0000
commit1375ed058fd9737100fe00f845a54fe95cde79d2 (patch)
tree588c3c3ebbca7af645a0ff4abfc12b9512cddc09 /src
parent36341a87e2480634d4a84b58532d13b22e1e5dfb (diff)
downloadmongo-1375ed058fd9737100fe00f845a54fe95cde79d2.tar.gz
SERVER-57899 Expose accumulator name to make it more convenient to switch on type of AccumulatorStatement
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/commands/mr_common.cpp3
-rw-r--r--src/mongo/db/pipeline/accumulation_statement.cpp5
-rw-r--r--src/mongo/db/pipeline/accumulation_statement.h18
-rw-r--r--src/mongo/db/pipeline/accumulator.h82
-rw-r--r--src/mongo/db/pipeline/accumulator_add_to_set.cpp4
-rw-r--r--src/mongo/db/pipeline/accumulator_avg.cpp4
-rw-r--r--src/mongo/db/pipeline/accumulator_exp_moving_avg.cpp3
-rw-r--r--src/mongo/db/pipeline/accumulator_first.cpp4
-rw-r--r--src/mongo/db/pipeline/accumulator_for_window_functions.h33
-rw-r--r--src/mongo/db/pipeline/accumulator_integral.cpp5
-rw-r--r--src/mongo/db/pipeline/accumulator_js_reduce.cpp27
-rw-r--r--src/mongo/db/pipeline/accumulator_js_reduce.h15
-rw-r--r--src/mongo/db/pipeline/accumulator_last.cpp4
-rw-r--r--src/mongo/db/pipeline/accumulator_merge_objects.cpp4
-rw-r--r--src/mongo/db/pipeline/accumulator_min_max.cpp6
-rw-r--r--src/mongo/db/pipeline/accumulator_push.cpp4
-rw-r--r--src/mongo/db/pipeline/accumulator_rank.cpp12
-rw-r--r--src/mongo/db/pipeline/accumulator_std_dev.cpp4
-rw-r--r--src/mongo/db/pipeline/accumulator_sum.cpp4
-rw-r--r--src/mongo/db/pipeline/document_source_bucket_auto.cpp3
-rw-r--r--src/mongo/db/pipeline/document_source_internal_unpack_bucket.cpp2
-rw-r--r--src/mongo/db/pipeline/expression.h2
22 files changed, 145 insertions, 103 deletions
diff --git a/src/mongo/db/commands/mr_common.cpp b/src/mongo/db/commands/mr_common.cpp
index 46a0a0e6284..3bef28fae6b 100644
--- a/src/mongo/db/commands/mr_common.cpp
+++ b/src/mongo/db/commands/mr_common.cpp
@@ -130,7 +130,8 @@ auto translateReduce(boost::intrusive_ptr<ExpressionContext> expCtx, std::string
AccumulationStatement jsReduce("value",
AccumulationExpression(std::move(initializer),
std::move(argument),
- std::move(reduceFactory)));
+ std::move(reduceFactory),
+ AccumulatorInternalJsReduce::kName));
auto groupKeyExpression =
ExpressionFieldPath::parse(expCtx.get(), "$emits.k", expCtx->variablesParseState);
return DocumentSourceGroup::create(expCtx,
diff --git a/src/mongo/db/pipeline/accumulation_statement.cpp b/src/mongo/db/pipeline/accumulation_statement.cpp
index 77981c189c4..3e83633e018 100644
--- a/src/mongo/db/pipeline/accumulation_statement.cpp
+++ b/src/mongo/db/pipeline/accumulation_statement.cpp
@@ -115,10 +115,9 @@ AccumulationStatement AccumulationStatement::parseAccumulationStatement(
auto&& parser =
AccumulationStatement::getParser(accName, expCtx->maxFeatureCompatibilityVersion);
- auto [initializer, argument, factory] = parser(expCtx, specElem, vps);
+ auto accExpr = parser(expCtx, specElem, vps);
- return AccumulationStatement(fieldName.toString(),
- AccumulationExpression(initializer, argument, factory));
+ return AccumulationStatement(fieldName.toString(), std::move(accExpr));
}
MONGO_INITIALIZER_GROUP(BeginAccumulatorRegistration, ("default"), ("EndAccumulatorRegistration"))
diff --git a/src/mongo/db/pipeline/accumulation_statement.h b/src/mongo/db/pipeline/accumulation_statement.h
index f621107421b..9ee7adb859f 100644
--- a/src/mongo/db/pipeline/accumulation_statement.h
+++ b/src/mongo/db/pipeline/accumulation_statement.h
@@ -102,8 +102,9 @@ namespace mongo {
struct AccumulationExpression {
AccumulationExpression(boost::intrusive_ptr<Expression> initializer,
boost::intrusive_ptr<Expression> argument,
- AccumulatorState::Factory factory)
- : initializer(initializer), argument(argument), factory(factory) {
+ AccumulatorState::Factory factory,
+ StringData name)
+ : initializer(initializer), argument(argument), factory(factory), name(name) {
invariant(this->initializer);
invariant(this->argument);
}
@@ -119,6 +120,12 @@ struct AccumulationExpression {
// A no argument function object that can be called to create an AccumulatorState.
const AccumulatorState::Factory factory;
+
+ // The name of the accumulator expression. It is the caller's responsibility to make sure the
+ // memory this points to does not get freed. This can best be accomplished by passing in a
+ // pointer to a string constant. This StringData is always required to point to a valid
+ // null-terminated string.
+ const StringData name;
};
/**
@@ -131,7 +138,7 @@ AccumulationExpression genericParseSingleExpressionAccumulator(ExpressionContext
VariablesParseState vps) {
auto initializer = ExpressionConstant::create(expCtx, Value(BSONNULL));
auto argument = Expression::parseOperand(expCtx, elem, vps);
- return {initializer, argument, [expCtx]() { return AccName::create(expCtx); }};
+ return {initializer, argument, [expCtx]() { return AccName::create(expCtx); }, AccName::kName};
}
/**
@@ -145,7 +152,10 @@ inline AccumulationExpression parseCountAccumulator(ExpressionContext* const exp
elem.type() == BSONType::Object && elem.Obj().isEmpty());
auto initializer = ExpressionConstant::create(expCtx, Value(BSONNULL));
auto argument = ExpressionConstant::create(expCtx, Value(1));
- return {initializer, argument, [expCtx]() { return AccumulatorSum::create(expCtx); }};
+ return {initializer,
+ argument,
+ [expCtx]() { return AccumulatorSum::create(expCtx); },
+ AccumulatorSum::kName};
}
/**
diff --git a/src/mongo/db/pipeline/accumulator.h b/src/mongo/db/pipeline/accumulator.h
index 0929a696567..63559fc3cae 100644
--- a/src/mongo/db/pipeline/accumulator.h
+++ b/src/mongo/db/pipeline/accumulator.h
@@ -158,6 +158,12 @@ private:
class AccumulatorAddToSet final : public AccumulatorState {
public:
+ static constexpr auto kName = "$addToSet"_sd;
+
+ const char* getOpName() const final {
+ return kName.rawData();
+ }
+
/**
* Creates a new $addToSet accumulator. If no memory limit is given, defaults to the value of
* the server parameter 'internalQueryMaxAddToSetBytes'.
@@ -167,7 +173,6 @@ public:
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);
@@ -187,11 +192,16 @@ private:
class AccumulatorFirst final : public AccumulatorState {
public:
+ static constexpr auto kName = "$first"_sd;
+
+ const char* getOpName() const final {
+ return kName.rawData();
+ }
+
explicit AccumulatorFirst(ExpressionContext* const expCtx);
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);
@@ -207,11 +217,16 @@ private:
class AccumulatorLast final : public AccumulatorState {
public:
+ static constexpr auto kName = "$last"_sd;
+
+ const char* getOpName() const final {
+ return kName.rawData();
+ }
+
explicit AccumulatorLast(ExpressionContext* const expCtx);
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);
@@ -226,11 +241,16 @@ private:
class AccumulatorSum final : public AccumulatorState {
public:
+ static constexpr auto kName = "$sum"_sd;
+
+ const char* getOpName() const final {
+ return kName.rawData();
+ }
+
explicit AccumulatorSum(ExpressionContext* const expCtx);
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);
@@ -260,7 +280,6 @@ public:
void processInternal(const Value& input, bool merging) final;
Value getValue(bool toBeMerged) final;
- const char* getOpName() const final;
void reset() final;
bool isAssociative() const final {
@@ -278,6 +297,12 @@ private:
class AccumulatorMax final : public AccumulatorMinMax {
public:
+ static constexpr auto kName = "$max"_sd;
+
+ const char* getOpName() const final {
+ return kName.rawData();
+ }
+
explicit AccumulatorMax(ExpressionContext* const expCtx)
: AccumulatorMinMax(expCtx, Sense::kMax) {}
static boost::intrusive_ptr<AccumulatorState> create(ExpressionContext* const expCtx);
@@ -285,6 +310,12 @@ public:
class AccumulatorMin final : public AccumulatorMinMax {
public:
+ static constexpr auto kName = "$min"_sd;
+
+ const char* getOpName() const final {
+ return kName.rawData();
+ }
+
explicit AccumulatorMin(ExpressionContext* const expCtx)
: AccumulatorMinMax(expCtx, Sense::kMin) {}
static boost::intrusive_ptr<AccumulatorState> create(ExpressionContext* const expCtx);
@@ -292,6 +323,12 @@ public:
class AccumulatorPush final : public AccumulatorState {
public:
+ static constexpr auto kName = "$push"_sd;
+
+ const char* getOpName() const final {
+ return kName.rawData();
+ }
+
/**
* Creates a new $push accumulator. If no memory limit is given, defaults to the value of the
* server parameter 'internalQueryMaxPushBytes'.
@@ -301,7 +338,6 @@ public:
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);
@@ -313,11 +349,16 @@ private:
class AccumulatorAvg final : public AccumulatorState {
public:
+ static constexpr auto kName = "$avg"_sd;
+
+ const char* getOpName() const final {
+ return kName.rawData();
+ }
+
explicit AccumulatorAvg(ExpressionContext* const expCtx);
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);
@@ -341,7 +382,6 @@ public:
void processInternal(const Value& input, bool merging) final;
Value getValue(bool toBeMerged) final;
- const char* getOpName() const final;
void reset() final;
private:
@@ -353,6 +393,12 @@ private:
class AccumulatorStdDevPop final : public AccumulatorStdDev {
public:
+ static constexpr auto kName = "$stdDevPop"_sd;
+
+ const char* getOpName() const final {
+ return kName.rawData();
+ }
+
explicit AccumulatorStdDevPop(ExpressionContext* const expCtx)
: AccumulatorStdDev(expCtx, false) {}
static boost::intrusive_ptr<AccumulatorState> create(ExpressionContext* const expCtx);
@@ -360,6 +406,12 @@ public:
class AccumulatorStdDevSamp final : public AccumulatorStdDev {
public:
+ static constexpr auto kName = "$stdDevSamp"_sd;
+
+ const char* getOpName() const final {
+ return kName.rawData();
+ }
+
explicit AccumulatorStdDevSamp(ExpressionContext* const expCtx)
: AccumulatorStdDev(expCtx, true) {}
static boost::intrusive_ptr<AccumulatorState> create(ExpressionContext* const expCtx);
@@ -367,11 +419,16 @@ public:
class AccumulatorMergeObjects : public AccumulatorState {
public:
+ static constexpr auto kName = "$mergeObjects"_sd;
+
+ const char* getOpName() const final {
+ return kName.rawData();
+ }
+
AccumulatorMergeObjects(ExpressionContext* const expCtx);
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);
@@ -382,11 +439,16 @@ private:
class AccumulatorExpMovingAvg : public AccumulatorState {
public:
+ static constexpr auto kName = "$expMovingAvg"_sd;
+
+ const char* getOpName() const final {
+ return kName.rawData();
+ }
+
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,
diff --git a/src/mongo/db/pipeline/accumulator_add_to_set.cpp b/src/mongo/db/pipeline/accumulator_add_to_set.cpp
index 1538ca2f7e6..08d746b184e 100644
--- a/src/mongo/db/pipeline/accumulator_add_to_set.cpp
+++ b/src/mongo/db/pipeline/accumulator_add_to_set.cpp
@@ -46,10 +46,6 @@ using std::vector;
REGISTER_ACCUMULATOR(addToSet, genericParseSingleExpressionAccumulator<AccumulatorAddToSet>);
REGISTER_REMOVABLE_WINDOW_FUNCTION(addToSet, AccumulatorAddToSet, WindowFunctionAddToSet);
-const char* AccumulatorAddToSet::getOpName() const {
- return "$addToSet";
-}
-
void AccumulatorAddToSet::processInternal(const Value& input, bool merging) {
auto addValue = [this](auto&& val) {
bool inserted = _set.insert(val).second;
diff --git a/src/mongo/db/pipeline/accumulator_avg.cpp b/src/mongo/db/pipeline/accumulator_avg.cpp
index b141b091074..daddd56f502 100644
--- a/src/mongo/db/pipeline/accumulator_avg.cpp
+++ b/src/mongo/db/pipeline/accumulator_avg.cpp
@@ -48,10 +48,6 @@ REGISTER_ACCUMULATOR(avg, genericParseSingleExpressionAccumulator<AccumulatorAvg
REGISTER_STABLE_EXPRESSION(avg, ExpressionFromAccumulator<AccumulatorAvg>::parse);
REGISTER_REMOVABLE_WINDOW_FUNCTION(avg, AccumulatorAvg, WindowFunctionAvg);
-const char* AccumulatorAvg::getOpName() const {
- return "$avg";
-}
-
namespace {
const char subTotalName[] = "subTotal";
const char subTotalErrorName[] = "subTotalError"; // Used for extra precision
diff --git a/src/mongo/db/pipeline/accumulator_exp_moving_avg.cpp b/src/mongo/db/pipeline/accumulator_exp_moving_avg.cpp
index 2f2dcc93d9e..491c5ee7964 100644
--- a/src/mongo/db/pipeline/accumulator_exp_moving_avg.cpp
+++ b/src/mongo/db/pipeline/accumulator_exp_moving_avg.cpp
@@ -44,9 +44,6 @@ namespace mongo {
using boost::intrusive_ptr;
REGISTER_WINDOW_FUNCTION(expMovingAvg, mongo::window_function::ExpressionExpMovingAvg::parse);
-const char* AccumulatorExpMovingAvg::getOpName() const {
- return "$expMovingAvg";
-}
void AccumulatorExpMovingAvg::processInternal(const Value& input, bool merging) {
tassert(5433600, "$expMovingAvg can't be merged", !merging);
diff --git a/src/mongo/db/pipeline/accumulator_first.cpp b/src/mongo/db/pipeline/accumulator_first.cpp
index cfb22aef242..5673db2540a 100644
--- a/src/mongo/db/pipeline/accumulator_first.cpp
+++ b/src/mongo/db/pipeline/accumulator_first.cpp
@@ -40,10 +40,6 @@ using boost::intrusive_ptr;
REGISTER_ACCUMULATOR(first, genericParseSingleExpressionAccumulator<AccumulatorFirst>);
-const char* AccumulatorFirst::getOpName() const {
- return "$first";
-}
-
void AccumulatorFirst::processInternal(const Value& input, bool merging) {
/* only remember the first value seen */
if (!_haveFirst) {
diff --git a/src/mongo/db/pipeline/accumulator_for_window_functions.h b/src/mongo/db/pipeline/accumulator_for_window_functions.h
index c3205a70e2e..63abd175ad1 100644
--- a/src/mongo/db/pipeline/accumulator_for_window_functions.h
+++ b/src/mongo/db/pipeline/accumulator_for_window_functions.h
@@ -74,6 +74,8 @@ private:
class AccumulatorCovarianceSamp final : public AccumulatorCovariance {
public:
+ static constexpr auto kName = "$covarianceSamp"_sd;
+
explicit AccumulatorCovarianceSamp(ExpressionContext* const expCtx)
: AccumulatorCovariance(expCtx, true) {}
static boost::intrusive_ptr<AccumulatorState> create(ExpressionContext* const expCtx);
@@ -81,6 +83,8 @@ public:
class AccumulatorCovariancePop final : public AccumulatorCovariance {
public:
+ static constexpr auto kName = "$covariancePop"_sd;
+
explicit AccumulatorCovariancePop(ExpressionContext* const expCtx)
: AccumulatorCovariance(expCtx, false) {}
static boost::intrusive_ptr<AccumulatorState> create(ExpressionContext* const expCtx);
@@ -102,9 +106,14 @@ protected:
class AccumulatorRank : public AccumulatorRankBase {
public:
+ static constexpr auto kName = "$rank"_sd;
+
+ const char* getOpName() const final {
+ return kName.rawData();
+ }
+
explicit AccumulatorRank(ExpressionContext* const expCtx) : AccumulatorRankBase(expCtx) {}
void processInternal(const Value& input, bool merging) final;
- const char* getOpName() const final;
static boost::intrusive_ptr<AccumulatorState> create(ExpressionContext* const expCtx);
void reset() final;
@@ -114,23 +123,39 @@ private:
class AccumulatorDocumentNumber : public AccumulatorRankBase {
public:
+ static constexpr auto kName = "$documentNumber"_sd;
+
+ const char* getOpName() const final {
+ return kName.rawData();
+ }
+
explicit AccumulatorDocumentNumber(ExpressionContext* const expCtx)
: AccumulatorRankBase(expCtx) {}
void processInternal(const Value& input, bool merging) final;
- const char* getOpName() const final;
static boost::intrusive_ptr<AccumulatorState> create(ExpressionContext* const expCtx);
};
class AccumulatorDenseRank : public AccumulatorRankBase {
public:
+ static constexpr auto kName = "$denseRank"_sd;
+
+ const char* getOpName() const final {
+ return kName.rawData();
+ }
+
explicit AccumulatorDenseRank(ExpressionContext* const expCtx) : AccumulatorRankBase(expCtx) {}
void processInternal(const Value& input, bool merging) final;
- const char* getOpName() const final;
static boost::intrusive_ptr<AccumulatorState> create(ExpressionContext* const expCtx);
};
class AccumulatorIntegral : public AccumulatorForWindowFunctions {
public:
+ static constexpr auto kName = "$integral"_sd;
+
+ const char* getOpName() const final {
+ return kName.rawData();
+ }
+
explicit AccumulatorIntegral(ExpressionContext* const expCtx,
boost::optional<long long> unitMillis = boost::none);
@@ -138,8 +163,6 @@ public:
Value getValue(bool toBeMerged) final;
void reset() final;
- const char* getOpName() const final;
-
static boost::intrusive_ptr<AccumulatorState> create(
ExpressionContext* const expCtx, boost::optional<long long> unitMillis = boost::none);
diff --git a/src/mongo/db/pipeline/accumulator_integral.cpp b/src/mongo/db/pipeline/accumulator_integral.cpp
index f17908ddeb2..e3943751ae6 100644
--- a/src/mongo/db/pipeline/accumulator_integral.cpp
+++ b/src/mongo/db/pipeline/accumulator_integral.cpp
@@ -67,9 +67,4 @@ boost::intrusive_ptr<AccumulatorState> AccumulatorIntegral::create(
ExpressionContext* const expCtx, boost::optional<long long> unitMillis) {
return new AccumulatorIntegral(expCtx, unitMillis);
}
-
-const char* AccumulatorIntegral::getOpName() const {
- return "$integral";
-}
-
} // namespace mongo
diff --git a/src/mongo/db/pipeline/accumulator_js_reduce.cpp b/src/mongo/db/pipeline/accumulator_js_reduce.cpp
index e7192465d7c..4e23b219692 100644
--- a/src/mongo/db/pipeline/accumulator_js_reduce.cpp
+++ b/src/mongo/db/pipeline/accumulator_js_reduce.cpp
@@ -40,8 +40,7 @@ REGISTER_ACCUMULATOR(_internalJsReduce, AccumulatorInternalJsReduce::parseIntern
AccumulationExpression AccumulatorInternalJsReduce::parseInternalJsReduce(
ExpressionContext* const expCtx, BSONElement elem, VariablesParseState vps) {
uassert(31326,
- str::stream() << kAccumulatorName << " requires a document argument, but found "
- << elem.type(),
+ str::stream() << kName << " requires a document argument, but found " << elem.type(),
elem.type() == BSONType::Object);
BSONObj obj = elem.embeddedObject();
@@ -55,16 +54,16 @@ AccumulationExpression AccumulatorInternalJsReduce::parseInternalJsReduce(
argument = Expression::parseOperand(expCtx, element, vps);
} else {
uasserted(31243,
- str::stream() << "Invalid argument specified to " << kAccumulatorName << ": "
+ str::stream() << "Invalid argument specified to " << kName << ": "
<< element.toString());
}
}
uassert(31245,
- str::stream() << kAccumulatorName
+ str::stream() << kName
<< " requires 'eval' argument, recieved input: " << obj.toString(false),
!funcSource.empty());
uassert(31349,
- str::stream() << kAccumulatorName
+ str::stream() << kName
<< " requires 'data' argument, recieved input: " << obj.toString(false),
argument);
@@ -73,13 +72,16 @@ AccumulationExpression AccumulatorInternalJsReduce::parseInternalJsReduce(
};
auto initializer = ExpressionConstant::create(expCtx, Value(BSONNULL));
- return {std::move(initializer), std::move(argument), std::move(factory)};
+ return {std::move(initializer),
+ std::move(argument),
+ std::move(factory),
+ AccumulatorInternalJsReduce::kName};
}
std::string AccumulatorInternalJsReduce::parseReduceFunction(BSONElement func) {
uassert(
31244,
- str::stream() << kAccumulatorName
+ str::stream() << kName
<< " requires the 'eval' argument to be of type string, or code but found "
<< func.type(),
func.type() == BSONType::String || func.type() == BSONType::Code);
@@ -91,7 +93,7 @@ void AccumulatorInternalJsReduce::processInternal(const Value& input, bool mergi
return;
}
uassert(31242,
- str::stream() << kAccumulatorName << " requires a document argument, but found "
+ str::stream() << kName << " requires a document argument, but found "
<< input.getType(),
input.getType() == BSONType::Object);
Document data = input.getDocument();
@@ -102,7 +104,7 @@ void AccumulatorInternalJsReduce::processInternal(const Value& input, bool mergi
uassert(
31251,
- str::stream() << kAccumulatorName
+ str::stream() << kName
<< " requires the 'data' argument to have a 'k' and 'v' field. Instead found"
<< data.toString(),
data.computeSize() == 2ull && !kField.missing() && !vField.missing());
@@ -188,7 +190,7 @@ void AccumulatorInternalJsReduce::reset() {
Document AccumulatorInternalJsReduce::serialize(boost::intrusive_ptr<Expression> initializer,
boost::intrusive_ptr<Expression> argument,
bool explain) const {
- return DOC(getOpName() << DOC("data" << argument->serialize(explain) << "eval" << _funcSource));
+ return DOC(kName << DOC("data" << argument->serialize(explain) << "eval" << _funcSource));
}
REGISTER_ACCUMULATOR(accumulator, AccumulatorJs::parse);
@@ -237,7 +239,7 @@ Document AccumulatorJs::serialize(boost::intrusive_ptr<Expression> initializer,
args.addField("finalize", Value(*_finalize));
}
args.addField("lang", Value("js"_sd));
- return DOC(getOpName() << args.freeze());
+ return DOC(kName << args.freeze());
}
AccumulationExpression AccumulatorJs::parse(ExpressionContext* const expCtx,
@@ -314,7 +316,8 @@ AccumulationExpression AccumulatorJs::parse(ExpressionContext* const expCtx,
finalize = std::move(finalize)]() {
return new AccumulatorJs(expCtx, init, accumulate, merge, finalize);
};
- return {std::move(initArgs), std::move(accumulateArgs), std::move(factory)};
+ return {
+ std::move(initArgs), std::move(accumulateArgs), std::move(factory), AccumulatorJs::kName};
}
Value AccumulatorJs::getValue(bool toBeMerged) {
diff --git a/src/mongo/db/pipeline/accumulator_js_reduce.h b/src/mongo/db/pipeline/accumulator_js_reduce.h
index f0725055266..3b8f6adfa8d 100644
--- a/src/mongo/db/pipeline/accumulator_js_reduce.h
+++ b/src/mongo/db/pipeline/accumulator_js_reduce.h
@@ -40,7 +40,11 @@ namespace mongo {
class AccumulatorInternalJsReduce final : public AccumulatorState {
public:
- static constexpr auto kAccumulatorName = "$_internalJsReduce"_sd;
+ static constexpr auto kName = "$_internalJsReduce"_sd;
+
+ const char* getOpName() const final {
+ return kName.rawData();
+ }
static boost::intrusive_ptr<AccumulatorState> create(ExpressionContext* const expCtx,
StringData funcSource);
@@ -54,10 +58,6 @@ public:
_memUsageBytes = sizeof(*this);
}
- const char* getOpName() const final {
- return kAccumulatorName.rawData();
- }
-
void processInternal(const Value& input, bool merging) final;
Value getValue(bool toBeMerged) final;
@@ -78,9 +78,10 @@ private:
class AccumulatorJs final : public AccumulatorState {
public:
- static constexpr auto kAccumulatorName = "$accumulator"_sd;
+ static constexpr auto kName = "$accumulator"_sd;
+
const char* getOpName() const final {
- return kAccumulatorName.rawData();
+ return kName.rawData();
}
// An AccumulatorState instance only owns its "static" arguments: those that don't need to be
diff --git a/src/mongo/db/pipeline/accumulator_last.cpp b/src/mongo/db/pipeline/accumulator_last.cpp
index a1dade1aefb..dc5bd49b859 100644
--- a/src/mongo/db/pipeline/accumulator_last.cpp
+++ b/src/mongo/db/pipeline/accumulator_last.cpp
@@ -40,10 +40,6 @@ using boost::intrusive_ptr;
REGISTER_ACCUMULATOR(last, genericParseSingleExpressionAccumulator<AccumulatorLast>);
-const char* AccumulatorLast::getOpName() const {
- return "$last";
-}
-
void AccumulatorLast::processInternal(const Value& input, bool merging) {
/* always remember the last value seen */
_last = input;
diff --git a/src/mongo/db/pipeline/accumulator_merge_objects.cpp b/src/mongo/db/pipeline/accumulator_merge_objects.cpp
index 72943b74a70..43e2979e3ab 100644
--- a/src/mongo/db/pipeline/accumulator_merge_objects.cpp
+++ b/src/mongo/db/pipeline/accumulator_merge_objects.cpp
@@ -45,10 +45,6 @@ REGISTER_ACCUMULATOR(mergeObjects,
genericParseSingleExpressionAccumulator<AccumulatorMergeObjects>);
REGISTER_STABLE_EXPRESSION(mergeObjects, ExpressionFromAccumulator<AccumulatorMergeObjects>::parse);
-const char* AccumulatorMergeObjects::getOpName() const {
- return "$mergeObjects";
-}
-
intrusive_ptr<AccumulatorState> AccumulatorMergeObjects::create(ExpressionContext* const expCtx) {
return new AccumulatorMergeObjects(expCtx);
}
diff --git a/src/mongo/db/pipeline/accumulator_min_max.cpp b/src/mongo/db/pipeline/accumulator_min_max.cpp
index b6d7c3db74d..06f8d5543d9 100644
--- a/src/mongo/db/pipeline/accumulator_min_max.cpp
+++ b/src/mongo/db/pipeline/accumulator_min_max.cpp
@@ -48,12 +48,6 @@ REGISTER_STABLE_EXPRESSION(min, ExpressionFromAccumulator<AccumulatorMin>::parse
REGISTER_REMOVABLE_WINDOW_FUNCTION(max, AccumulatorMax, WindowFunctionMax);
REGISTER_REMOVABLE_WINDOW_FUNCTION(min, AccumulatorMin, WindowFunctionMin);
-const char* AccumulatorMinMax::getOpName() const {
- if (_sense == Sense::kMin)
- return "$min";
- return "$max";
-}
-
void AccumulatorMinMax::processInternal(const Value& input, bool merging) {
// nullish values should have no impact on result
if (!input.nullish()) {
diff --git a/src/mongo/db/pipeline/accumulator_push.cpp b/src/mongo/db/pipeline/accumulator_push.cpp
index cf3daa632a7..3bb375c8d97 100644
--- a/src/mongo/db/pipeline/accumulator_push.cpp
+++ b/src/mongo/db/pipeline/accumulator_push.cpp
@@ -46,10 +46,6 @@ using std::vector;
REGISTER_ACCUMULATOR(push, genericParseSingleExpressionAccumulator<AccumulatorPush>);
REGISTER_REMOVABLE_WINDOW_FUNCTION(push, AccumulatorPush, WindowFunctionPush);
-const char* AccumulatorPush::getOpName() const {
- return "$push";
-}
-
void AccumulatorPush::processInternal(const Value& input, bool merging) {
if (!merging) {
if (!input.missing()) {
diff --git a/src/mongo/db/pipeline/accumulator_rank.cpp b/src/mongo/db/pipeline/accumulator_rank.cpp
index 1ac0912744a..cbe4522c8cc 100644
--- a/src/mongo/db/pipeline/accumulator_rank.cpp
+++ b/src/mongo/db/pipeline/accumulator_rank.cpp
@@ -53,10 +53,6 @@ REGISTER_WINDOW_FUNCTION(
documentNumber,
mongo::window_function::ExpressionFromRankAccumulator<AccumulatorDocumentNumber>::parse);
-const char* AccumulatorRank::getOpName() const {
- return "$rank";
-}
-
void AccumulatorRank::processInternal(const Value& input, bool merging) {
tassert(5417001, "$rank can't be merged", !merging);
if (!_lastInput ||
@@ -70,20 +66,12 @@ void AccumulatorRank::processInternal(const Value& input, bool merging) {
}
}
-const char* AccumulatorDocumentNumber::getOpName() const {
- return "$documentNumber";
-}
-
void AccumulatorDocumentNumber::processInternal(const Value& input, bool merging) {
tassert(5417002, "$documentNumber can't be merged", !merging);
// DocumentNumber doesn't need to keep track of what we just saw.
++_lastRank;
}
-const char* AccumulatorDenseRank::getOpName() const {
- return "$denseRank";
-}
-
void AccumulatorDenseRank::processInternal(const Value& input, bool merging) {
tassert(5417003, "$denseRank can't be merged", !merging);
if (!_lastInput ||
diff --git a/src/mongo/db/pipeline/accumulator_std_dev.cpp b/src/mongo/db/pipeline/accumulator_std_dev.cpp
index dd64ffb8750..ce2e5ac3e77 100644
--- a/src/mongo/db/pipeline/accumulator_std_dev.cpp
+++ b/src/mongo/db/pipeline/accumulator_std_dev.cpp
@@ -49,10 +49,6 @@ REGISTER_STABLE_EXPRESSION(stdDevSamp, ExpressionFromAccumulator<AccumulatorStdD
REGISTER_REMOVABLE_WINDOW_FUNCTION(stdDevPop, AccumulatorStdDevPop, WindowFunctionStdDevPop);
REGISTER_REMOVABLE_WINDOW_FUNCTION(stdDevSamp, AccumulatorStdDevSamp, WindowFunctionStdDevSamp);
-const char* AccumulatorStdDev::getOpName() const {
- return (_isSamp ? "$stdDevSamp" : "$stdDevPop");
-}
-
void AccumulatorStdDev::processInternal(const Value& input, bool merging) {
if (!merging) {
// non numeric types have no impact on standard deviation
diff --git a/src/mongo/db/pipeline/accumulator_sum.cpp b/src/mongo/db/pipeline/accumulator_sum.cpp
index 587a1b86e88..b25fe3939ae 100644
--- a/src/mongo/db/pipeline/accumulator_sum.cpp
+++ b/src/mongo/db/pipeline/accumulator_sum.cpp
@@ -54,10 +54,6 @@ REGISTER_ACCUMULATOR_WITH_MIN_VERSION(
REGISTER_WINDOW_FUNCTION(count, window_function::parseCountWindowFunction);
-const char* AccumulatorSum::getOpName() const {
- return "$sum";
-}
-
namespace {
const char subTotalName[] = "subTotal";
const char subTotalErrorName[] = "subTotalError"; // Used for extra precision.
diff --git a/src/mongo/db/pipeline/document_source_bucket_auto.cpp b/src/mongo/db/pipeline/document_source_bucket_auto.cpp
index 413d98c157a..76296516b27 100644
--- a/src/mongo/db/pipeline/document_source_bucket_auto.cpp
+++ b/src/mongo/db/pipeline/document_source_bucket_auto.cpp
@@ -411,7 +411,8 @@ intrusive_ptr<DocumentSourceBucketAuto> DocumentSourceBucketAuto::create(
"count",
AccumulationExpression(ExpressionConstant::create(pExpCtx.get(), Value(BSONNULL)),
ExpressionConstant::create(pExpCtx.get(), Value(1)),
- [pExpCtx] { return AccumulatorSum::create(pExpCtx.get()); }));
+ [pExpCtx] { return AccumulatorSum::create(pExpCtx.get()); },
+ AccumulatorSum::kName));
}
return new DocumentSourceBucketAuto(pExpCtx,
groupByExpression,
diff --git a/src/mongo/db/pipeline/document_source_internal_unpack_bucket.cpp b/src/mongo/db/pipeline/document_source_internal_unpack_bucket.cpp
index 8ef46b46734..581057f9742 100644
--- a/src/mongo/db/pipeline/document_source_internal_unpack_bucket.cpp
+++ b/src/mongo/db/pipeline/document_source_internal_unpack_bucket.cpp
@@ -787,7 +787,7 @@ DocumentSourceInternalUnpackBucket::rewriteGroupByMinMax(Pipeline::SourceContain
bool suitable = true;
std::vector<AccumulationStatement> accumulationStatements;
for (const AccumulationStatement& stmt : groupPtr->getAccumulatedFields()) {
- const std::string& op = stmt.makeAccumulator()->getOpName();
+ const auto op = stmt.expr.name;
const bool isMin = op == "$min";
const bool isMax = op == "$max";
diff --git a/src/mongo/db/pipeline/expression.h b/src/mongo/db/pipeline/expression.h
index df9e1802e8e..a9dd5f7d485 100644
--- a/src/mongo/db/pipeline/expression.h
+++ b/src/mongo/db/pipeline/expression.h
@@ -529,7 +529,7 @@ public:
}
const char* getOpName() const final {
- return AccumulatorState(this->getExpressionContext()).getOpName();
+ return AccumulatorState::kName.rawData();
}
void acceptVisitor(ExpressionMutableVisitor* visitor) final {