Arithmetic expression support - #3
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements
ArithmeticExpression(CoreModel 2.11.0), split between the server and the existing in-memory fallback by where the semantics can be honored.Server-side: add, subtract, multiply
(a <op> b) <operator> constantcompiles to a guarded aggregation$exprfilter:The
$isNumberguard is load-bearing:$addof a missing or null field yieldsnull, and aggregation comparisons ranknullbelow every number — so without it,arithmetic < constantwould spuriously match rows where the operand is absent. CoreModel's engine yieldsnilfor such rows, which matches no comparison; the guard reproduces that. Key paths become$-prefixed field paths, so composite elements ($location.latitude) work unchanged.In-memory: divide and modulus
Routed through the existing
requiresInMemoryEvaluationfallback (the same path custom functions use), because the server cannot match CoreModel's semantics:$divideaborts the whole query on division by zero, where CoreModel yieldsnil(comparison false)$dividealways produces floating point — no truncating integer division$modcomputes on floats, where CoreModel defines remainder for integers onlyThe fallback evaluation mirrors CoreModel's internal engine exactly (integer ops stay integer with truncating division, mixed/float as
Double,nilon zero division, overflow, or float modulus). A division nested anywhere in an expression tree routes the request to memory.Also fixed
testMongoDBregistered itsMongoClientcleanupdeferafter the first throwingawait, so with no server listening the client deinitialized unclosed and MongoSwift's assertion killed the test process (SIGTRAP). The defer now comes first; the test fails cleanly with a connection error instead.Testing
13 server-free tests: the
$exprdocument shapes (flat, nested, composite-element operands), memory-routing for divide/modulus including nested, native routing for add/subtract/multiply, and the in-memory semantics (truncation, zero division across operators, float promotion, float modulus, non-numeric operands). The end-to-end$exprpath against a livemongodremains unexercised, as with the composite work.