summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/sbe_stage_builder_accumulator_test.cpp
diff options
context:
space:
mode:
authorYoonsoo Kim <yoonsoo.kim@mongodb.com>2021-09-20 16:22:16 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-09-20 17:10:45 +0000
commitfa121d14a011a5d7c9607b5df068bb61b81a2b0b (patch)
tree1d924812790039c9e1735a420cfe4fbf8c5d0e6f /src/mongo/db/query/sbe_stage_builder_accumulator_test.cpp
parent7ee2e01e5d95a9b925fa1964b4f9f6151a9806bd (diff)
downloadmongo-fa121d14a011a5d7c9607b5df068bb61b81a2b0b.tar.gz
SERVER-60030 Fix group stage builder bugs
Diffstat (limited to 'src/mongo/db/query/sbe_stage_builder_accumulator_test.cpp')
-rw-r--r--src/mongo/db/query/sbe_stage_builder_accumulator_test.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/mongo/db/query/sbe_stage_builder_accumulator_test.cpp b/src/mongo/db/query/sbe_stage_builder_accumulator_test.cpp
index 958532ed927..382b954d707 100644
--- a/src/mongo/db/query/sbe_stage_builder_accumulator_test.cpp
+++ b/src/mongo/db/query/sbe_stage_builder_accumulator_test.cpp
@@ -248,6 +248,28 @@ TEST_F(SbeStageBuilderGroupTest, TestGroupMultipleAccumulators) {
<< 3 << "firstb" << 3 << "lastb" << 3)));
}
+TEST_F(SbeStageBuilderGroupTest, AccSkippingFinalStepAfterAvg) {
+ auto docs = std::vector<BSONArray>{BSON_ARRAY(BSON("a" << 1 << "b" << 1)),
+ BSON_ARRAY(BSON("a" << 1 << "b" << 2)),
+ BSON_ARRAY(BSON("a" << 2 << "b" << 3))};
+ runGroupAggregationTest(R"({_id: null, x: {$avg: "$b"}, y: {$last: "$b"}})",
+ docs,
+ BSON_ARRAY(BSON("_id" << BSONNULL << "x" << 6 / 3.0 << "y" << 3)));
+ // An accumulator skipping the final step after multiple $avg.
+ runGroupAggregationTest(
+ R"({_id: null, x: {$avg: "$b"}, y: {$avg: "$b"}, z: {$last: "$b"}})",
+ docs,
+ BSON_ARRAY(BSON("_id" << BSONNULL << "x" << 6 / 3.0 << "y" << 6 / 3.0 << "z" << 3)));
+}
+
+TEST_F(SbeStageBuilderGroupTest, NullForMissingGroupBySlot) {
+ auto docs = std::vector<BSONArray>{BSON_ARRAY(BSON("a" << 1 << "b" << 1)),
+ BSON_ARRAY(BSON("a" << 2 << "b" << 3))};
+ // _id: null is returned if the group-by field is missing.
+ runGroupAggregationTest(
+ R"({_id: "$z", x: {$first: "$b"}})", docs, BSON_ARRAY(BSON("_id" << BSONNULL << "x" << 1)));
+}
+
TEST_F(SbeStageBuilderGroupTest, TestGroupNoAccumulators) {
auto docs = std::vector<BSONArray>{BSON_ARRAY(BSON("a" << 1 << "b" << 1)),
BSON_ARRAY(BSON("a" << 1 << "b" << 2)),