diff options
author | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2021-05-13 14:39:49 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-05-13 20:57:23 +0000 |
commit | b28b53d23843c0e42e0751673c76088a3e7e60fa (patch) | |
tree | 237b856746156cf5295e553579d76ef1a5353ce5 /src/mongo/db/pipeline/window_function | |
parent | e93440951afbe91dc10702e279d8201a2e938d97 (diff) | |
download | mongo-b28b53d23843c0e42e0751673c76088a3e7e60fa.tar.gz |
SERVER-56685 Stricter parsing for $expMovingAvg, require an explicit 'sortBy' and 'alpha' between 0 and 1
Diffstat (limited to 'src/mongo/db/pipeline/window_function')
-rw-r--r-- | src/mongo/db/pipeline/window_function/window_function_expression.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/mongo/db/pipeline/window_function/window_function_expression.cpp b/src/mongo/db/pipeline/window_function/window_function_expression.cpp index df551b0db93..49be1652cfc 100644 --- a/src/mongo/db/pipeline/window_function/window_function_expression.cpp +++ b/src/mongo/db/pipeline/window_function/window_function_expression.cpp @@ -86,6 +86,7 @@ boost::intrusive_ptr<Expression> ExpressionExpMovingAvg::parse( << kInputArg << "' field, and either an '" << kNArg << "' field or an '" << kAlphaArg << "' field", subObj.nFields() == 2 && subObj.hasField(kInputArg)); + uassert(ErrorCodes::FailedToParse, "$expMovingAvg requires an explicit 'sortBy'", sortBy); input = ::mongo::Expression::parseOperand(expCtx, subObj[kInputArg], expCtx->variablesParseState); // ExpMovingAvg is always unbounded to current. @@ -112,11 +113,13 @@ boost::intrusive_ptr<Expression> ExpressionExpMovingAvg::parse( uassert(ErrorCodes::FailedToParse, str::stream() << "'" << kAlphaArg << "' must be a number", subObj[kAlphaArg].isNumber()); - return make_intrusive<ExpressionExpMovingAvg>(expCtx, - std::string(kAccName), - std::move(input), - std::move(bounds), - subObj[kAlphaArg].numberDecimal()); + auto alpha = subObj[kAlphaArg].numberDecimal(); + uassert(ErrorCodes::FailedToParse, + str::stream() << "'" << kAlphaArg << "' must be between 0 and 1 (exclusive), found " + << subObj[kAlphaArg], + alpha.isGreater(Decimal128(0)) && alpha.isLess(Decimal128(1.0))); + return make_intrusive<ExpressionExpMovingAvg>( + expCtx, std::string(kAccName), std::move(input), std::move(bounds), std::move(alpha)); } else { uasserted(ErrorCodes::FailedToParse, str::stream() << "Got unrecognized field in $expMovingAvg" |