feat(core): add arithmetic functions ADD/SUBTRACT/MULTIPLY/DIVIDE/NEGATE - #193
Merged
brunomendola merged 1 commit intoJul 11, 2026
Merged
Conversation
Expose row-level arithmetic as prefix functions, consistent with the existing ABS/SQRT/MOD design and reusing the functionCall -> Function -> *FunctionMapper pipeline (no grammar precedence changes). - add/multiply variadic (min 2, associative), subtract/divide binary (left-associative, binary-only backends), negate unary - JPA: CriteriaBuilder sum/diff/prod/quot/neg (variadic fold like concat) - MongoDB: $add/$subtract/$multiply/$divide; negate via $multiply[-1, x] - Elasticsearch: unsupported (throws), consistent with all functions - Java factory helpers on Querity; end-to-end tests on H2 + embedded Mongo Refs queritylib#192 Co-Authored-By: Claude Opus 4.8 <[email protected]>
brunomendola
approved these changes
Jul 11, 2026
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.
Summary
Implements #192: row-level arithmetic as prefix functions, consistent with the existing
ABS/SQRT/MODdesign. No grammar precedence machinery is introduced — the new functions slot into the existingfunctionCall→Function→*FunctionMapperpipeline.CriteriaBuilder)ADD(a, b, ...)sum(fold)$addSUBTRACT(a, b)a - bdiff$subtractMULTIPLY(a, b, ...)prod(fold)$multiplyDIVIDE(a, b)a / bquot$divideNEGATE(a)-aneg$multiply [-1, x]Arity rationale:
ADD/MULTIPLYare associative and commutative, so they map 1:1 to the natively-variadic$add/$multiply(and to a JPA fold, exactly likeCONCATtoday).SUBTRACT/DIVIDEare only left-associative and their backends are binary-only, so they stay strictly binary; chains are expressed by nesting:ADD(MULTIPLY(price, 1.22), fee).Examples
Changes
Functionenum —ADD(-1),SUBTRACT(2),MULTIPLY(-1),DIVIDE(2),NEGATE(1)inARITHMETIC;getMinimumArguments()returns 2 for the variadic arithmetic functionsfunctionArgsalready supports variadic args, nested calls and numeric literals, so no other grammar changeJpaFunctionMapper—cb.sum/diff/prod/quot/neg;add/multiplyfold likeconcatMongodbFunctionMapper—$add/$subtract/$multiply/$divide;negateas$multiply [-1, x]Querityfactory —add(...),subtract(a, b),multiply(...),divide(a, b),negate(a)UnsupportedOperationException), consistent with every other functionNotes
DIVIDEmaps tocb.quot, which follows the backend's integer-division semantics for integer operands; documented in the enum Javadoc. Happy to coerce to decimal instead if preferred.Testing
FunctionCallarity validation, parser (variadic, nested, decimal literals, case-insensitive), JPA mapper (incl. fold verification), MongoDB mapper (document shapes), factory helpers, Elasticsearch unsupportedQuerityGenericTestSuite(ADD/SUBTRACT/MULTIPLYin filters) — green on H2, PostgreSQL (Testcontainers) and MongoDB./mvnw verify— JaCoCo per-class coverage checks met on all touched modulesCloses #192
🤖 Generated with Claude Code