summaryrefslogtreecommitdiff
path: root/jstests/core/timeseries
diff options
context:
space:
mode:
authorSvilen Mihaylov <svilen.mihaylov@mongodb.com>2022-08-30 09:32:07 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-30 14:54:30 +0000
commit3f7efc7fbe74cbe5155b6a8229392b0261d59b28 (patch)
treec59622ed314f0475de782f3dd583df6707d7a784 /jstests/core/timeseries
parentce2dbe9a4a3baaf2a346fd517ca82937100804e6 (diff)
downloadmongo-3f7efc7fbe74cbe5155b6a8229392b0261d59b28.tar.gz
SERVER-67780 Incorrect $group rewrite for timeseries collection when the accumulator uses meta field
Diffstat (limited to 'jstests/core/timeseries')
-rw-r--r--jstests/core/timeseries/timeseries_groupby_reorder.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/jstests/core/timeseries/timeseries_groupby_reorder.js b/jstests/core/timeseries/timeseries_groupby_reorder.js
new file mode 100644
index 00000000000..29d07f8b4fa
--- /dev/null
+++ b/jstests/core/timeseries/timeseries_groupby_reorder.js
@@ -0,0 +1,43 @@
+/**
+ * Test the behavior of $group on time-series collections.
+ *
+ * @tags: [
+ * directly_against_shardsvrs_incompatible,
+ * does_not_support_stepdowns,
+ * does_not_support_transactions,
+ * requires_fcv_61,
+ * ]
+ */
+(function() {
+"use strict";
+
+load("jstests/libs/fixture_helpers.js");
+load("jstests/core/timeseries/libs/timeseries.js");
+
+const coll = db.timeseries_groupby_reorder;
+coll.drop();
+
+assert.commandWorked(
+ db.createCollection(coll.getName(), {timeseries: {metaField: "meta", timeField: "t"}}));
+
+const t = new Date();
+assert.commandWorked(coll.insert({_id: 0, t: t, b: 1, c: 1}));
+assert.commandWorked(coll.insert({_id: 0, t: t, b: 2, c: 2}));
+assert.commandWorked(coll.insert({_id: 0, t: t, b: 3, c: 3}));
+
+// Test reordering the groupby and internal unpack buckets.
+if (!isMongos(db)) {
+ const res = coll.explain("queryPlanner").aggregate([
+ {$group: {_id: '$meta', accmin: {$min: '$b'}, accmax: {$max: '$c'}}}
+ ]);
+
+ assert.docEq(res.stages[1], {
+ "$group":
+ {_id: "$meta", accmin: {"$min": "$control.min.b"}, accmax: {"$max": "$control.max.c"}}
+ });
+}
+
+const res = coll.aggregate([{$group: {_id: '$meta', accmin: {$min: '$b'}, accmax: {$max: '$c'}}}])
+ .toArray();
+assert.docEq(res, [{"_id": null, "accmin": 1, "accmax": 3}]);
+})();