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 /jstests/aggregation/sources/setWindowFields | |
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 'jstests/aggregation/sources/setWindowFields')
-rw-r--r-- | jstests/aggregation/sources/setWindowFields/exp_moving_avg.js | 88 |
1 files changed, 82 insertions, 6 deletions
diff --git a/jstests/aggregation/sources/setWindowFields/exp_moving_avg.js b/jstests/aggregation/sources/setWindowFields/exp_moving_avg.js index a0a5c517c91..3e5f89a3eeb 100644 --- a/jstests/aggregation/sources/setWindowFields/exp_moving_avg.js +++ b/jstests/aggregation/sources/setWindowFields/exp_moving_avg.js @@ -134,7 +134,8 @@ assert.commandFailedWithCode(db.runCommand({ } } }, - ] + ], + cursor: {}, }), ErrorCodes.FailedToParse); assert.commandFailedWithCode(db.runCommand({ @@ -150,7 +151,8 @@ assert.commandFailedWithCode(db.runCommand({ } } }, - ] + ], + cursor: {}, }), ErrorCodes.FailedToParse); assert.commandFailedWithCode(db.runCommand({ @@ -166,7 +168,8 @@ assert.commandFailedWithCode(db.runCommand({ } } }, - ] + ], + cursor: {}, }), ErrorCodes.FailedToParse); assert.commandFailedWithCode(db.runCommand({ @@ -182,7 +185,8 @@ assert.commandFailedWithCode(db.runCommand({ } } }, - ] + ], + cursor: {}, }), ErrorCodes.FailedToParse); assert.commandFailedWithCode(db.runCommand({ @@ -199,7 +203,8 @@ assert.commandFailedWithCode(db.runCommand({ } } }, - ] + ], + cursor: {}, }), ErrorCodes.FailedToParse); assert.commandFailedWithCode(db.runCommand({ @@ -215,7 +220,78 @@ assert.commandFailedWithCode(db.runCommand({ } } }, - ] + ], + cursor: {}, }), ErrorCodes.FailedToParse); + +// Fails if an explicit 'sortBy' is not given. +assert.commandFailedWithCode(db.runCommand({ + aggregate: coll.getName(), + pipeline: [ + { + $setWindowFields: { + output: { + expMovAvg: { + $expMovingAvg: {input: "$price", N: 1}, + }, + } + } + }, + ], + cursor: {}, +}), + ErrorCodes.FailedToParse); + +// Fails if 'alpha' is not between 0 and 1, exclusive. +assert.commandFailedWithCode(db.runCommand({ + aggregate: coll.getName(), + pipeline: [ + { + $setWindowFields: { + sortBy: {_id: 1}, + output: { + expMovAvg: { + $expMovingAvg: {input: "$price", alpha: 1.0}, + }, + } + } + }, + ], + cursor: {}, +}), + ErrorCodes.FailedToParse); +assert.commandFailedWithCode(db.runCommand({ + aggregate: coll.getName(), + pipeline: [ + { + $setWindowFields: { + sortBy: {_id: 1}, + output: { + expMovAvg: { + $expMovingAvg: {input: "$price", alpha: 0.0}, + }, + } + } + }, + ], + cursor: {}, +}), + ErrorCodes.FailedToParse); +assert.commandWorked(db.runCommand({ + aggregate: coll.getName(), + pipeline: [ + { + $setWindowFields: { + sortBy: {_id: 1}, + output: { + expMovAvg: { + $expMovingAvg: {input: "$price", alpha: NumberDecimal("1.0E-1")}, + }, + } + } + }, + ], + cursor: {}, +})); })(); |