summaryrefslogtreecommitdiff
path: root/jstests/cqf/group.js
blob: 4af1ad6b021d34f10c31aae9023bc7a99fcc5cba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(function() {
"use strict";

load("jstests/libs/optimizer_utils.js");  // For checkCascadesOptimizerEnabled.
if (!checkCascadesOptimizerEnabled(db)) {
    jsTestLog("Skipping test because the optimizer is not enabled");
    return;
}

const coll = db.cqf_group;
coll.drop();

assert.commandWorked(coll.insert([
    {a: 1, b: 1, c: 1},
    {a: 1, b: 2, c: 2},
    {a: 1, b: 2, c: 3},
    {a: 2, b: 1, c: 4},
    {a: 2, b: 1, c: 5},
    {a: 2, b: 2, c: 6},
]));

const res = coll.explain("executionStats").aggregate([
    {$group: {_id: {a: '$a', b: '$b'}, sum: {$sum: '$c'}, avg: {$avg: '$c'}}}
]);
assert.eq("GroupBy", res.queryPlanner.winningPlan.optimizerPlan.child.child.nodeType);
assert.eq(4, res.executionStats.nReturned);
}());