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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/**
* Test how $densify desugars.
*
* @tags: [
* # $mergeCursors was added to explain output in 5.3.
* requires_fcv_53,
* # We're testing the explain plan, not the query results, so the facet passthrough would fail.
* do_not_wrap_aggregations_in_facets,
* ]
*/
(function() {
"use strict";
load("jstests/libs/fixture_helpers.js");
load("jstests/aggregation/extras/utils.js"); // For anyEq and
// desugarSingleStageAggregation.
const coll = db[jsTestName()];
coll.insert({});
// Implicit partition fields and sort are generated.
assert.eq(desugarSingleStageAggregation(
db, coll, {$densify: {field: "a", range: {step: 1.0, bounds: "full"}}}),
[
{$sort: {sortKey: {a: 1}}},
{
$_internalDensify:
{field: "a", partitionByFields: [], range: {step: 1.0, bounds: "full"}}
},
]);
// PartitionByFields are prepended to the sortKey if "partition" is specified.
assert.eq(
desugarSingleStageAggregation(db, coll, {
$densify:
{field: "a", partitionByFields: ["b", "c"], range: {step: 1.0, bounds: "partition"}}
}),
[
{$sort: {sortKey: {b: 1, c: 1, a: 1}}},
{
$_internalDensify:
{field: "a", partitionByFields: ["b", "c"], range: {step: 1.0, bounds: "partition"}}
},
]);
// PartitionByFields are not prepended to the sortKey if "full" is specified.
assert.eq(
desugarSingleStageAggregation(db, coll, {
$densify: {field: "a", partitionByFields: ["b", "c"], range: {step: 1.0, bounds: "full"}}
}),
[
{$sort: {sortKey: {a: 1}}},
{
$_internalDensify:
{field: "a", partitionByFields: ["b", "c"], range: {step: 1.0, bounds: "full"}}
},
]);
// PartitionByFields are prepended to the sortKey if numeric bounds are specified.
assert.eq(
desugarSingleStageAggregation(db, coll, {
$densify: {field: "a", partitionByFields: ["b", "c"], range: {step: 1.0, bounds: [-10, 0]}}
}),
[
{$sort: {sortKey: {b: 1, c: 1, a: 1}}},
{
$_internalDensify:
{field: "a", partitionByFields: ["b", "c"], range: {step: 1.0, bounds: [-10, 0]}}
},
]);
// PartitionByFields are prepended to the sortKey if date bounds are specified.
assert.eq(desugarSingleStageAggregation(db, coll, {
$densify: {
field: "a",
partitionByFields: ["b", "c"],
range: {
step: 1.0,
bounds: [new ISODate("2020-01-03"), new ISODate("2020-01-04")],
unit: "day"
}
}
}),
[
{$sort: {sortKey: {b: 1, c: 1, a: 1}}},
{
$_internalDensify: {
field: "a",
partitionByFields: ["b", "c"],
range: {
step: 1.0,
bounds: [new ISODate("2020-01-03"), new ISODate("2020-01-04")],
unit: "day"
}
}
},
]);
})();
|