[SERVER-6125] aggregation $sort cannot process heterogenous data types (asserts) Created: 19/Jun/12  Updated: 15/Apr/13  Resolved: 11/Dec/12

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

Type: Improvement Priority: Major - P3
Reporter: Aaron Staple Assignee: Mathias Stearn
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on DOCS-1022 Document the rules for sorting hetero... Closed
Related
is related to SERVER-6206 need a policy for incompatible types ... Closed
Backwards Compatibility: Fully Compatible
Participants:

 Description   

Value::compare does not compare heterogenous data types (however the different numeric types can be compared).

In particular this can cause issues if a value may or may not be within an array (even if it's a nested field).

        // CW TODO for now, only compare like values
        uassert(16016, str::stream() <<
                "can't compare values of BSON types " << lType <<
                " and " << rType,
                lType == rType);

This can cause assertions when trying to $sort different data types for example:

 
c = db.c;
c.drop();
 
c.save( { a:1 } );
c.save( { a:true } );
 
printjson( c.aggregate( { $sort:{ a:1 } } ) );
 

And in particular it can also cause problems when some fields are within arrays (even nested):

c = db.c;
c.drop();
 
c.save( { a:{ b:1 } } );
c.save( { a:[ { b:2 } ] } );
 
printjson( c.aggregate( { $sort:{ 'a.b':1 } } ) );

Observed behavior: An assertion is raised when an attempt is made to sort a field containing different data types in different documents.
Expected behavior: The results are sorted, without an assertion, in spite of the different data types.



 Comments   
Comment by auto [ 27/Feb/13 ]

Author:

{u'date': u'2013-02-27T05:58:36Z', u'name': u'Andre de Frere', u'email': u'andre.defrere@10gen.com'}

Message: SERVER-6125 - moved jstest to correct location

Signed-off-by: Ian Whalen <ian.whalen@gmail.com>
Branch: master
https://github.com/mongodb/mongo/commit/82c8b3262103a89f0d29c51989f5063718b2ae5c

Comment by auto [ 14/Feb/13 ]

Author:

{u'date': u'2013-01-30T22:56:36Z', u'name': u'Andre de Frere', u'email': u'andre.defrere@gmail.com'}

Message: SERVER-6125 - Add tests for heterogeneous $sort operations in aggregation

Signed-off-by: Ian Whalen <ian.whalen@gmail.com>
Branch: master
https://github.com/mongodb/mongo/commit/3face9156090a46c14f281a1f684fa07a6110363

Comment by auto [ 11/Dec/12 ]

Author:

{u'date': u'2012-11-28T00:34:39Z', u'email': u'mathias@10gen.com', u'name': u'Mathias Stearn'}

Message: Make Value::compare behave the same as BSONElement::woCompare

Related cases:
SERVER-6125 $sort on heterogeneous types
SERVER-6126 Value::compare transitivity (now exactly as broken as BSONObj)
Branch: master
https://github.com/mongodb/mongo/commit/323f3924fbb835c8180d95153fb976c4a224157b

Comment by auto [ 11/Dec/12 ]

Author:

{u'date': u'2012-11-26T19:48:16Z', u'email': u'mathias@10gen.com', u'name': u'Mathias Stearn'}

Message: Move logic from BSONElement::canonicalType to canonicalBSONType free function

Prep for SERVER-6125 - Agg $sort on heterogeneous types
Branch: master
https://github.com/mongodb/mongo/commit/8f263678cd71db0d5208ec7783f84f2bdd262be2

Generated at Thu Feb 08 03:10:49 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.