[SERVER-27100] ExpressionObject does not optimize itself to a constant expression Created: 17/Nov/16  Updated: 06/Jun/18  Resolved: 02/Mar/18

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

Type: Task Priority: Major - P3
Reporter: Charlie Swanson Assignee: Charlie Swanson
Resolution: Done Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
is documented by DOCS-11427 Docs for SERVER-27100: ExpressionObje... Closed
Backwards Compatibility: Fully Compatible
Participants:

 Description   

An ExpressionObject's implementation of optimize() is missing an optimization where if all of the values in the object are constant, the entire ExpressionObject can be replaced with an ExpressionConstant representing the object literal.

This can cause an confusing error message when using the $bucket stage, since $bucket ensures all entries of the boundaries array are constants:

> db.baz.find()
{ "_id" : ObjectId("582e293f38b7ba11ec92eda8"), "a" : { "b" : 1, "c" : 1 } }
{ "_id" : ObjectId("582e293f38b7ba11ec92eda9"), "a" : { "b" : 1, "c" : 2 } }
 
// This fails, implying the object literals are not constants:
> db.baz.aggregate([{$bucket: {groupBy: "$a", boundaries: [{b: 1, c: 1}, {b: 1, c: 2}, {b: 2, c: 3}]}}])
assert: command failed: {
	"ok" : 0,
	"errmsg" : "The $bucket 'boundaries' field must be an array of constant values, but found value: { b: 1.0, c: 1.0 }.",
	"code" : 40191,
	"codeName" : "Location40191"
} : aggregate failed
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:16:14
assert.commandWorked@src/mongo/shell/assert.js:370:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1319:5
@(shell):1:1
 
2016-11-17T17:05:06.583-0500 E QUERY    [main] Error: command failed: {
	"ok" : 0,
	"errmsg" : "The $bucket 'boundaries' field must be an array of constant values, but found value: { b: 1.0, c: 1.0 }.",
	"code" : 40191,
	"codeName" : "Location40191"
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:16:14
assert.commandWorked@src/mongo/shell/assert.js:370:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1319:5
@(shell):1:1
 
// If the objects are wrapped in a $literal, the $bucket succeeds:
> db.baz.aggregate([{$bucket: {groupBy: "$a", boundaries: [{$literal: {b: 1, c: 1}}, {$literal: {b: 1, c: 2}}, {$literal: {b: 2, c: 3}}]}}])
{ "_id" : { "b" : 1, "c" : 1 }, "count" : 1 }
{ "_id" : { "b" : 1, "c" : 2 }, "count" : 1 }



 Comments   
Comment by Githook User [ 02/Mar/18 ]

Author:

{'email': 'KevinCybura@gmail.com', 'name': 'KevinCybura', 'username': 'KevinCybura'}

Message: SERVER-27100 Optimize all-constant ExpressionObject to a constant.

Closes #1213

Signed-off-by: Charlie Swanson <charlie.swanson@mongodb.com>
Branch: master
https://github.com/mongodb/mongo/commit/c6a81454240e682304cd576ea41c03ffabea7119

Comment by Charlie Swanson [ 14/Feb/18 ]

Assigning to myself. There's a pull request from Kevin Cybura, a CUNY student I'm working with.

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