[SERVER-6196] 'can't add two dates together' assertion during constant folding Created: 24/Jun/12  Updated: 08/Mar/13  Resolved: 21/Dec/12

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

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

Issue Links:
Depends
depends on SERVER-6239 Better semantics for $add and $subtra... Closed
Related
is related to SERVER-6206 need a policy for incompatible types ... Closed
is related to SERVER-6240 Disable math with Dates in agg Closed
Participants:

 Description   

In general we seem to support concatenation of multiple dates with strings but not addition of multiple dates.

Observed behavior: uassert if an attempt is made to add two dates as part of constant folding, even if the folded value would be unused because of a non constant string value.
Expected behavior: No uassert in this case.

Test:

c = db.c;
c.drop();
 
c.save( { x:' ' } );
 
// No uassert when concatenating multiple constants.
printjson( c.aggregate( { $project:{ a:{ $add:[ new Date(), ' ', new Date() ] } } } ) );
// uassert when concatenating date constants (constant folding) and a non constant string.
printjson( c.aggregate( { $project:{ a:{ $add:[ new Date(), '$x', new Date() ] } } } ) );



 Comments   
Comment by Mathias Stearn [ 21/Dec/12 ]

This bug no longer applies as all $expressions that support constant folding are correctly associative and commutative.

Comment by Aaron Staple [ 18/Dec/12 ]

redbeard0531 I haven't really looked at the new code, but I'd say just make sure there aren't any cases where changing an expression value from a constant to a field path (or the other way around) changes whether the expression asserts or not, due to constant folding. If there aren't any such cases, I'd just resolve this ticket as gone away or something.

Comment by Mathias Stearn [ 17/Dec/12 ]

aaron This command is no longer valid since you can't use $add with strings, nor can you have more than 1 Date in a $add expression. Should this test be converted to the new $concat operator for concatenating strings or do you think it no longer applies?

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