diff options
author | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2021-05-24 09:35:22 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-05-24 21:00:21 +0000 |
commit | c7f0e955947f30d328781cd039eaee85aa8664aa (patch) | |
tree | d8859f00c5d34e795fa8923df8be0ee9ee093050 | |
parent | e465a2c8dcc8d8f0676eaf266e809a71d946c07c (diff) | |
download | mongo-c7f0e955947f30d328781cd039eaee85aa8664aa.tar.gz |
SERVER-57148 Pass variables states to input evaluation in removable range executor
(cherry picked from commit 52501e767b89130fe2aa0d6bd9a8b3ba1fdced00)
-rw-r--r-- | jstests/aggregation/sources/setWindowFields/range.js | 27 | ||||
-rw-r--r-- | src/mongo/db/pipeline/window_function/window_function_exec_removable_range.cpp | 2 |
2 files changed, 28 insertions, 1 deletions
diff --git a/jstests/aggregation/sources/setWindowFields/range.js b/jstests/aggregation/sources/setWindowFields/range.js index 7826662b28a..6ab49b242cf 100644 --- a/jstests/aggregation/sources/setWindowFields/range.js +++ b/jstests/aggregation/sources/setWindowFields/range.js @@ -233,4 +233,31 @@ assert.sameMembers(run([range('unbounded', -3)]), [ {x: 3, y: [0, 0, 0, 0]}, {x: 3, y: [0, 0, 0, 0]}, ]); + +// Test variable evaluation for input expressions. +assert.sameMembers( + run([ + { + $setWindowFields: { + partitionBy: "$partition", + sortBy: {x: 1}, + output: { + y: { + $sum: {$filter: {input: [], as: 'num', cond: {$gte: ['$$num', 2]}}}, + window: {range: [-1, 1]} + }, + } + } + }, + {$unset: '_id'} + ]), + [ + {x: 0, y: 0}, + {x: 0, y: 0}, + {x: 0, y: 0}, + {x: 0, y: 0}, + {x: 3, y: 0}, + {x: 3, y: 0}, + {x: 3, y: 0}, + ]); })(); diff --git a/src/mongo/db/pipeline/window_function/window_function_exec_removable_range.cpp b/src/mongo/db/pipeline/window_function/window_function_exec_removable_range.cpp index 746baeb44fb..8518e4a864a 100644 --- a/src/mongo/db/pipeline/window_function/window_function_exec_removable_range.cpp +++ b/src/mongo/db/pipeline/window_function/window_function_exec_removable_range.cpp @@ -105,7 +105,7 @@ void WindowFunctionExecRemovableRange::update() { if (added) { auto [lower, upper] = *added; for (auto i = lower; i <= upper; ++i) { - addValue(_input->evaluate(*_iter[i], nullptr)); + addValue(_input->evaluate(*_iter[i], &_input->getExpressionContext()->variables)); } } if (removed) { |