summaryrefslogtreecommitdiff
path: root/jstests/aggregation/sources/setWindowFields
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/aggregation/sources/setWindowFields')
-rw-r--r--jstests/aggregation/sources/setWindowFields/collation.js2
-rw-r--r--jstests/aggregation/sources/setWindowFields/derivative.js76
-rw-r--r--jstests/aggregation/sources/setWindowFields/optimize.js8
3 files changed, 46 insertions, 40 deletions
diff --git a/jstests/aggregation/sources/setWindowFields/collation.js b/jstests/aggregation/sources/setWindowFields/collation.js
index 4568e36f908..235ccd7aaf8 100644
--- a/jstests/aggregation/sources/setWindowFields/collation.js
+++ b/jstests/aggregation/sources/setWindowFields/collation.js
@@ -30,7 +30,7 @@ let results =
collation)
.toArray();
// Test document order before $_internalSetWindowFields rather than $setWindowFields output order.
-assert.docEq(results[0].arr, ["10", "3", "2"]);
+assert.docEq(["10", "3", "2"], results[0].arr);
// Test that partitionBy and window function respect collation.
results =
diff --git a/jstests/aggregation/sources/setWindowFields/derivative.js b/jstests/aggregation/sources/setWindowFields/derivative.js
index a57af814b30..aeb2339d15b 100644
--- a/jstests/aggregation/sources/setWindowFields/derivative.js
+++ b/jstests/aggregation/sources/setWindowFields/derivative.js
@@ -99,24 +99,26 @@ result = coll.aggregate([
{$sort: {time: 1}},
])
.toArray();
-assert.docEq(result, [
- // The first document looks behind 3, but can't go any further back than time: 0.
- // It also looks ahead 1. So the points it compares are time: 0 and time: 1.
- {time: 0, y: 100, dy: +5},
- // The second document gets time: 0 and time: 2.
- {time: 1, y: 105, dy: +8 / 2},
- // The third gets time: 0 and time: 3.
- {time: 2, y: 108, dy: +8 / 3},
- // This is the first document whose left endpoint lies within the partition.
- // So this one, and the next few, all have fully-populated windows.
- {time: 3, y: 108, dy: +15 / 4},
- {time: 4, y: 115, dy: +10 / 4},
- {time: 5, y: 115, dy: +10 / 4},
- {time: 6, y: 118, dy: +10 / 4},
- // For the last document, there is no document at offset +1, so it sees
- // time: 4 and time: 7.
- {time: 7, y: 118, dy: +3 / 3},
-]);
+assert.docEq(
+ [
+ // The first document looks behind 3, but can't go any further back than time: 0.
+ // It also looks ahead 1. So the points it compares are time: 0 and time: 1.
+ {time: 0, y: 100, dy: +5},
+ // The second document gets time: 0 and time: 2.
+ {time: 1, y: 105, dy: +8 / 2},
+ // The third gets time: 0 and time: 3.
+ {time: 2, y: 108, dy: +8 / 3},
+ // This is the first document whose left endpoint lies within the partition.
+ // So this one, and the next few, all have fully-populated windows.
+ {time: 3, y: 108, dy: +15 / 4},
+ {time: 4, y: 115, dy: +10 / 4},
+ {time: 5, y: 115, dy: +10 / 4},
+ {time: 6, y: 118, dy: +10 / 4},
+ // For the last document, there is no document at offset +1, so it sees
+ // time: 4 and time: 7.
+ {time: 7, y: 118, dy: +3 / 3},
+ ],
+ result);
// Because the derivative is the same irrespective of sort order (as long as we reexpress the
// bounds) we can compare this result with the result of the previous aggregation.
const resultDesc =
@@ -133,7 +135,7 @@ const resultDesc =
{$sort: {time: 1}},
])
.toArray();
-assert.docEq(result, resultDesc);
+assert.docEq(resultDesc, result);
// Example with range-based bounds.
coll.drop();
@@ -158,14 +160,16 @@ result = coll.aggregate([
{$sort: {time: 1}},
])
.toArray();
-assert.docEq(result, [
- {time: 0, y: 10, dy: null},
- {time: 10, y: 12, dy: (12 - 10) / (10 - 0)},
- {time: 11, y: 15, dy: (15 - 12) / (11 - 10)},
- {time: 12, y: 19, dy: (19 - 12) / (12 - 10)},
- {time: 13, y: 24, dy: (24 - 12) / (13 - 10)},
- {time: 20, y: 30, dy: (30 - 12) / (20 - 10)},
-]);
+assert.docEq(
+ [
+ {time: 0, y: 10, dy: null},
+ {time: 10, y: 12, dy: (12 - 10) / (10 - 0)},
+ {time: 11, y: 15, dy: (15 - 12) / (11 - 10)},
+ {time: 12, y: 19, dy: (19 - 12) / (12 - 10)},
+ {time: 13, y: 24, dy: (24 - 12) / (13 - 10)},
+ {time: 20, y: 30, dy: (30 - 12) / (20 - 10)},
+ ],
+ result);
// 'unit' only supports 'week' and smaller.
coll.drop();
@@ -377,12 +381,14 @@ result = coll.aggregate([
{$sort: {time: 1}},
])
.toArray();
-assert.docEq(result, [
- {time: ISODate("2020-01-01T00:00:00.00Z"), y: 10, dy: null},
- {time: ISODate("2020-01-01T00:00:10.00Z"), y: 12, dy: (12 - 10) / (10 - 0)},
- {time: ISODate("2020-01-01T00:00:11.00Z"), y: 15, dy: (15 - 12) / (11 - 10)},
- {time: ISODate("2020-01-01T00:00:12.00Z"), y: 19, dy: (19 - 12) / (12 - 10)},
- {time: ISODate("2020-01-01T00:00:13.00Z"), y: 24, dy: (24 - 12) / (13 - 10)},
- {time: ISODate("2020-01-01T00:00:20.00Z"), y: 30, dy: (30 - 12) / (20 - 10)},
-]);
+assert.docEq(
+ [
+ {time: ISODate("2020-01-01T00:00:00.00Z"), y: 10, dy: null},
+ {time: ISODate("2020-01-01T00:00:10.00Z"), y: 12, dy: (12 - 10) / (10 - 0)},
+ {time: ISODate("2020-01-01T00:00:11.00Z"), y: 15, dy: (15 - 12) / (11 - 10)},
+ {time: ISODate("2020-01-01T00:00:12.00Z"), y: 19, dy: (19 - 12) / (12 - 10)},
+ {time: ISODate("2020-01-01T00:00:13.00Z"), y: 24, dy: (24 - 12) / (13 - 10)},
+ {time: ISODate("2020-01-01T00:00:20.00Z"), y: 30, dy: (30 - 12) / (20 - 10)},
+ ],
+ result);
})();
diff --git a/jstests/aggregation/sources/setWindowFields/optimize.js b/jstests/aggregation/sources/setWindowFields/optimize.js
index 10afd74d9cc..0b250c2980f 100644
--- a/jstests/aggregation/sources/setWindowFields/optimize.js
+++ b/jstests/aggregation/sources/setWindowFields/optimize.js
@@ -47,7 +47,7 @@ const explain1 = coll.explain().aggregate([
// Redundant $sort should be removed.
assert.eq(1, numberOfStages(explain1, '$sort'), explain1);
// We keep the more specific sort.
-assert.docEq(getAggPlanStages(explain1, '$sort'), [{$sort: {sortKey: {a: 1, b: 1}}}], explain1);
+assert.docEq([{$sort: {sortKey: {a: 1, b: 1}}}], getAggPlanStages(explain1, '$sort'), explain1);
const explain2 = coll.explain().aggregate([
{$_internalInhibitOptimization: {}},
@@ -77,7 +77,7 @@ const explain3 = coll.explain().aggregate([
// $sort should be swapped with $_internalSetWindowFields, and the extra one removed.
assert.eq(1, numberOfStages(explain3, '$sort'), explain3);
// The sort we keep should be the more specific one.
-assert.docEq(getAggPlanStages(explain3, '$sort'), [{$sort: {sortKey: {a: 1, b: -1}}}], explain3);
+assert.docEq([{$sort: {sortKey: {a: 1, b: -1}}}], getAggPlanStages(explain3, '$sort'), explain3);
const explain4 = coll.explain().aggregate([
{$_internalInhibitOptimization: {}},
@@ -178,7 +178,7 @@ const explain10 = coll.explain().aggregate([
]);
assert.eq(1, numberOfStages(explain10, '$sort'), explain10);
assert.docEq(
- getAggPlanStages(explain10, '$sort'), [{$sort: {sortKey: {a: 1, b: 1, c: 1}}}], explain10);
+ [{$sort: {sortKey: {a: 1, b: 1, c: 1}}}], getAggPlanStages(explain10, '$sort'), explain10);
// Multiple compatible sorts are pushed down.
const explain11 = coll.explain().aggregate([
@@ -195,7 +195,7 @@ const explain11 = coll.explain().aggregate([
]);
assert.eq(1, numberOfStages(explain11, '$sort'), explain11);
assert.docEq(
- getAggPlanStages(explain11, '$sort'), [{$sort: {sortKey: {a: 1, b: 1, c: 1}}}], explain11);
+ [{$sort: {sortKey: {a: 1, b: 1, c: 1}}}], getAggPlanStages(explain11, '$sort'), explain11);
// An incompatible $meta sort should not be dropped or pushed down.
coll.createIndex({'$**': 'text'});