diff options
author | zixuan.zhuang <zixuan.zhuang@mongodb.com> | 2022-08-17 19:03:40 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-17 20:44:50 +0000 |
commit | 5f8f59cd20901e9de9edb5eb5f33ea72f1fc1ef7 (patch) | |
tree | b838fd0e3d996e4e7bf27105030c3b24f42aaf16 /jstests | |
parent | d4280eab7a5215aeb06d040f614a1f2b2ca7266a (diff) | |
download | mongo-5f8f59cd20901e9de9edb5eb5f33ea72f1fc1ef7.tar.gz |
SERVER-68543 Make operator type left associate for date
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/aggregation/add_with_date.js | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/jstests/aggregation/add_with_date.js b/jstests/aggregation/add_with_date.js index cdddb122e5f..03f61d2edd5 100644 --- a/jstests/aggregation/add_with_date.js +++ b/jstests/aggregation/add_with_date.js @@ -1,5 +1,5 @@ // Test $add with date -// TODO SERVER-68543,SERVER-67282: to remove this tag after fix. +// TODO SERVER-68544: to remove this tag after fix. // @tags: [do_not_wrap_aggregations_in_facets] (function() { "use strict"; @@ -69,22 +69,10 @@ assert.eq(ISODate("2019-01-30T07:30:10.957Z"), getResultOfExpression({$add: ["$int32Val", "$dateVal"]})); // Addition with a date and multiple values of differing data types. -// TODO SERVER-68543: classic and sbe returns different values now, should update after fix. -if (isSBEEnabled) { - assert.eq( - ISODate("2019-01-30T07:30:12.597Z"), - getResultOfExpression({$add: ["$dateVal", "$decimalVal", "$doubleVal", "$int64Val"]})); - assert.eq( - ISODate("2019-01-30T07:30:12.597Z"), - getResultOfExpression({$add: ["$decimalVal", "$dateVal", "$doubleVal", "$int64Val"]})); -} else { - assert.eq( - ISODate("2019-01-30T07:30:12.596Z"), - getResultOfExpression({$add: ["$dateVal", "$decimalVal", "$doubleVal", "$int64Val"]})); - assert.eq( - ISODate("2019-01-30T07:30:12.596Z"), - getResultOfExpression({$add: ["$decimalVal", "$dateVal", "$doubleVal", "$int64Val"]})); -} +assert.eq(ISODate("2019-01-30T07:30:12.597Z"), + getResultOfExpression({$add: ["$dateVal", "$decimalVal", "$doubleVal", "$int64Val"]})); +assert.eq(ISODate("2019-01-30T07:30:12.597Z"), + getResultOfExpression({$add: ["$decimalVal", "$dateVal", "$doubleVal", "$int64Val"]})); assert.eq(ISODate("2019-01-30T07:30:12.596Z"), getResultOfExpression({$add: ["$decimalVal", "$doubleVal", "$int64Val", "$dateVal"]})); // The result of an addition must remain in the range of int64_t in order to convert back to a Date; @@ -110,9 +98,6 @@ if (isSBEEnabled) { assert.throwsWithCode(() => getResultOfExpression({$add: ["$dateVal", "$overflowDecimal"]}), ErrorCodes.Overflow); assert.throwsWithCode( - () => getResultOfExpression({$add: ["$dateVal", "$overflowDouble", "$overflowDecimal"]}), - ErrorCodes.Overflow); - assert.throwsWithCode( () => getResultOfExpression({$add: ["$int64Val", "$dateVal", "$overflowDecimal"]}), ErrorCodes.Overflow); } else { @@ -121,10 +106,11 @@ if (isSBEEnabled) { const nanDate = new Date(""); assert.eq(nanDate, getResultOfExpression({$add: ["$dateVal", "$overflowDecimal"]})); assert.eq(nanDate, - getResultOfExpression({$add: ["$dateVal", "$overflowDouble", "$overflowDecimal"]})); - assert.eq(nanDate, getResultOfExpression({$add: ["$int64Val", "$dateVal", "$overflowDecimal"]})); } +assert.throwsWithCode( + () => getResultOfExpression({$add: ["$dateVal", "$overflowDouble", "$overflowDecimal"]}), + ErrorCodes.Overflow); // Adding a double-typed NaN to a date value. assert.throwsWithCode(() => getResultOfExpression({$add: ["$dateVal", "$nanDouble"]}), @@ -152,16 +138,21 @@ assert.throwsWithCode(() => getResultOfExpression({$add: ["$dateVal", "$doubleVa ErrorCodes.Overflow); // Addition with a date, and both types of NaN. -// TODO SERVER-68544: classic and sbe have different behavior now, should update after fix. -if (isSBEEnabled) { - assert.throwsWithCode( - () => getResultOfExpression({$add: ["$dateVal", "$nanDouble", "$nanDecimal"]}), - ErrorCodes.Overflow); -} else { - const nanDate = new Date(""); - assert.eq(nanDate, getResultOfExpression({$add: ["$dateVal", "$nanDouble", "$nanDecimal"]})); -} +assert.throwsWithCode( + () => getResultOfExpression({$add: ["$dateVal", "$nanDouble", "$nanDecimal"]}), + ErrorCodes.Overflow); // Throw error when there're two or more date in $add. assert.throwsWithCode(() => getResultOfExpression({$add: ["$dateVal", 1, "$dateVal"]}), 4974202); + +// Test very large long and verify that we're maintaining the precision of long arithmetic. +// 2397083434877565865 and 239708343487756586 both cast to the same double value from longs +assert.eq(ISODate("2019-01-30T07:30:10.958Z"), getResultOfExpression({ + $add: [ + "$dateVal", + NumberLong("2397083434877565865"), + "$doubleVal", + NumberLong("-2397083434877565864") + ] + })); }()); |