[DOCS-16507] Investigate changes in SERVER-39336: In order to be schema friendly, $mod output should be based only on input types, not values Created: 20/Nov/23  Updated: 22/Jan/24  Resolved: 17/Jan/24

Status: Closed
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: 7.3.0-rc0, Server_Docs_[20240122]

Type: Task Priority: Minor - P4
Reporter: Backlog - Core Eng Program Management Team Assignee: Lauren Tran
Resolution: Done Votes: 0
Labels: feature
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
documents SERVER-39336 In order to be schema friendly, $mod ... Closed
URL(s): https://www.mongodb.com/docs/manual/reference/operator/aggregation/mod/
Participants:
Days since reply: 11 weeks, 2 days ago
Story Points: 2

 Description   
Original Downstream Change Summary

The type of the result of a $mod expression is now determined solely from the input types; the exact input value will no longer lead to a narrower result type.

E.g., Previously $mod: [2, 1.1] would result in a double result, but $mod: [2, 1.0], would result in a integer, as the rhs happens to be convertible to an int without rounding error despite being of double type.

Now, the result type will always be the wider of the two input types.

If the existing behaviour was relied upon, users may now find that code expecting an int instead of a long or double needs to be updated to expect the appropriate type result - or to provide arguments as ints if applicable.

Description of Linked Ticket

$mod has a special condition if the right-hand-side is of non-integral type but of integral value.
https://github.com/mongodb/mongo/blob/8387824b3ac937b0489fcb94c590cc663b47348c/src/mongo/db/pipeline/expression.cpp#L2528
We should eliminate this condition from the conditional so that the output type of an arithmetic expression is based only on input types, not values. This has two benefits:
It causes a pipeline to output documents that are closer to a fixed schema.
Non-deterministicly-ordered input to grouping stages will no longer cause output of arbitrary type. This will eliminate the linked agg fuzzer issue.


Generated at Thu Feb 08 08:15:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.