diff options
author | Ted Tuckman <ted.tuckman@mongodb.com> | 2021-03-04 16:43:38 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-03-04 18:01:49 +0000 |
commit | ca1bf42db1f3057e55a312cfe95d49150a4c4cd6 (patch) | |
tree | c111728553a21e7c9cded494a32c7a8ebff75cdc /src | |
parent | 61f0251c5d0ef38d76ba5e26ce593b3d762e0f62 (diff) | |
download | mongo-ca1bf42db1f3057e55a312cfe95d49150a4c4cd6.tar.gz |
SERVER-54607 Add support for right unbounded windows in removable document executor
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/pipeline/window_function/window_function_exec_removable_document.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/pipeline/window_function/window_function_exec_test.cpp | 34 |
2 files changed, 31 insertions, 9 deletions
diff --git a/src/mongo/db/pipeline/window_function/window_function_exec_removable_document.cpp b/src/mongo/db/pipeline/window_function/window_function_exec_removable_document.cpp index 571c06eac30..2a724589360 100644 --- a/src/mongo/db/pipeline/window_function/window_function_exec_removable_document.cpp +++ b/src/mongo/db/pipeline/window_function/window_function_exec_removable_document.cpp @@ -53,7 +53,7 @@ WindowFunctionExecRemovableDocument::WindowFunctionExecRemovableDocument( stdx::visit( visit_helper::Overloaded{ [](const WindowBounds::Unbounded&) { - uasserted(5339801, "Right unbounded windows are not yet supported"); + // Pass. _upperBound defaults to boost::none which represents no upper bound. }, [&](const WindowBounds::Current&) { _upperBound = 0; }, [&](const int& upperIndex) { _upperBound = upperIndex; }, @@ -63,7 +63,9 @@ WindowFunctionExecRemovableDocument::WindowFunctionExecRemovableDocument( void WindowFunctionExecRemovableDocument::initialize() { int lowerBoundForInit = _lowerBound > 0 ? _lowerBound : 0; - for (int i = lowerBoundForInit; i <= _upperBound; ++i) { + // Run the loop until we hit the out of partition break (right unbounded) or we hit the upper + // bound. + for (int i = lowerBoundForInit; !_upperBound || i <= _upperBound.get(); ++i) { // If this is false, we're over the end of the partition. if (auto doc = (*this->_iter)[i]) { addValue(_input->evaluate(*doc, nullptr)); diff --git a/src/mongo/db/pipeline/window_function/window_function_exec_test.cpp b/src/mongo/db/pipeline/window_function/window_function_exec_test.cpp index a3238d8594e..3f36d25123d 100644 --- a/src/mongo/db/pipeline/window_function/window_function_exec_test.cpp +++ b/src/mongo/db/pipeline/window_function/window_function_exec_test.cpp @@ -270,14 +270,34 @@ TEST_F(WindowFunctionExecRemovableDocumentTest, DefaultValueWorksAsExpected) { ASSERT(mgr.getNext().nullish()); // Default value } -TEST_F(WindowFunctionExecRemovableDocumentTest, FunctionalityNotSupported) { +TEST_F(WindowFunctionExecRemovableDocumentTest, RightUnboundedDoesNotAddDocumentsDuringWindow) { const auto docs = std::deque<DocumentSource::GetNextResult>{ - Document{{"a", 3}}, Document{{"a", 2}}, Document{{"a", 1}}}; - ASSERT_THROWS_CODE( - createForFieldPath( - std::move(docs), "$a", WindowBounds::DocumentBased{1, WindowBounds::Unbounded{}}), - AssertionException, - 5339801); + Document{{"a", 3}}, Document{{"a", 2}}, Document{{"a", 1}}, Document{{"a", 17}}}; + auto mgr = createForFieldPath( + std::move(docs), + "$a", + WindowBounds::DocumentBased{WindowBounds::Current{}, WindowBounds::Unbounded{}}); + ASSERT_VALUE_EQ(Value(17), mgr.getNext()); + advanceIterator(); + ASSERT_VALUE_EQ(Value(17), mgr.getNext()); + advanceIterator(); + ASSERT_VALUE_EQ(Value(17), mgr.getNext()); + advanceIterator(); + ASSERT_VALUE_EQ(Value(17), mgr.getNext()); + advanceIterator(); + + const auto docsTwo = std::deque<DocumentSource::GetNextResult>{ + Document{{"a", 18}}, Document{{"a", 2}}, Document{{"a", 1}}, Document{{"a", 17}}}; + mgr = createForFieldPath( + std::move(docsTwo), "$a", WindowBounds::DocumentBased{-1, WindowBounds::Unbounded{}}); + ASSERT_VALUE_EQ(Value(18), mgr.getNext()); + advanceIterator(); + ASSERT_VALUE_EQ(Value(18), mgr.getNext()); + advanceIterator(); + ASSERT_VALUE_EQ(Value(17), mgr.getNext()); + advanceIterator(); + ASSERT_VALUE_EQ(Value(17), mgr.getNext()); + advanceIterator(); } TEST_F(WindowFunctionExecRemovableDocumentTest, EnsureFirstDocumentIsNotRemovedEarly) { |