[SERVER-63425] $setUnion convert NumberDecimal to NumberLong when pipeline optimization is turned off Created: 08/Feb/22  Updated: 09/Feb/22  Resolved: 09/Feb/22

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Alexander Ignatyev Assignee: Alexander Ignatyev
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File bf-24145.js    
Issue Links:
Depends
Operating System: ALL
Sprint: QO 2022-02-21
Participants:
Linked BF Score: 40

 Description   

It is applicable for Classic Execution Engine only. Test to reproduce: see the attached file.

const document = { "num": 29439 };
assert.commandWorked(coll.insertOne(document));
const pipeline = [{
    $bucketAuto: {
        groupBy: {$setUnion: [[NumberLong("0")], ["$num", NumberDecimal("-0")]]},
        buckets: NumberInt(18)
    }
}];

[js_test:bf24145] uncaught exception: Error: [[
[js_test:bf24145]       {
[js_test:bf24145]               "_id" : {
[js_test:bf24145]                       "min" : [
[js_test:bf24145]                               NumberDecimal("-0"),
[js_test:bf24145]                               29439
[js_test:bf24145]                       ],
[js_test:bf24145]                       "max" : [
[js_test:bf24145]                               NumberDecimal("-0"),
[js_test:bf24145]                               29439
[js_test:bf24145]                       ]
[js_test:bf24145]               },
[js_test:bf24145]               "count" : 1
[js_test:bf24145]       }
[js_test:bf24145] ]] != [[
[js_test:bf24145]       {
[js_test:bf24145]               "_id" : {
[js_test:bf24145]                       "min" : [
[js_test:bf24145]                               NumberLong(0),
[js_test:bf24145]                               29439
[js_test:bf24145]                       ],
[js_test:bf24145]                       "max" : [
[js_test:bf24145]                               NumberLong(0),
[js_test:bf24145]                               29439
[js_test:bf24145]                       ]
[js_test:bf24145]               },
[js_test:bf24145]               "count" : 1
[js_test:bf24145]       }
[js_test:bf24145] ]] are not equal :
[js_test:bf24145] doassert@src/mongo/shell/assert.js:20:14
[js_test:bf24145] assert.docEq@src/mongo/shell/assert.js:205:9
[js_test:bf24145] @jstests/bf24145.js:31:1
[js_test:bf24145] @jstests/bf24145.js:1:2



 Comments   
Comment by Alexander Ignatyev [ 09/Feb/22 ]

$setUnion is defined as a commutative operator (see ExpressionSetUnion::isCommutative) which means that the order of the operands does not matter.

ExpressionSetUnion::evaluate uses ValueSet to build a set of values. ValueSet uses semantics of Value type when all numeric types can be considered equal as long as they have the same value. This means that NumberLong("0") is considered to be equal Decimal("-0") for the are both numeric and have the same value.

Therefore, the behaviour explained in the ticket is expected.

Generated at Thu Feb 08 05:57:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.