PHOENIX-7757 : Support arithmetic with if_not_exists in bson SET update expression#2362
Merged
palashc merged 3 commits intoapache:masterfrom Feb 3, 2026
Merged
PHOENIX-7757 : Support arithmetic with if_not_exists in bson SET update expression#2362palashc merged 3 commits intoapache:masterfrom
palashc merged 3 commits intoapache:masterfrom
Conversation
virajjasani
approved these changes
Feb 3, 2026
| } | ||
|
|
||
| private static Number resolveSetOperand(BsonValue operand, BsonDocument bsonDocument) { | ||
| if (operand.isNumber()) { |
Contributor
There was a problem hiding this comment.
It seems in the latest BSON version, operand.isNumber() seems to be fixed. Otherwise, we follow this pattern everywhere: operand.isNumber() || operand.isDecimal128()
Comment on lines
+687
to
+688
| BsonValue resolved = resolveIfNotExists((BsonDocument) operand, bsonDocument); | ||
| return getNumberFromBsonNumber((BsonNumber) resolved); |
Contributor
There was a problem hiding this comment.
If one provides non-number data type with $IF_NOT_EXISTS, it will fail. This is expected, looks good.
Comment on lines
+647
to
+656
| } else if (doc.containsKey("$ADD")) { | ||
| BsonArray operands = doc.getArray("$ADD"); | ||
| Number result = resolveSetOperand(operands.get(0), bsonDocument); | ||
| result = addNum(result, resolveSetOperand(operands.get(1), bsonDocument)); | ||
| return getBsonNumberFromNumber(result); | ||
| } else if (doc.containsKey("$SUBTRACT")) { | ||
| BsonArray operands = doc.getArray("$SUBTRACT"); | ||
| Number result = resolveSetOperand(operands.get(0), bsonDocument); | ||
| result = subtractNum(result, resolveSetOperand(operands.get(1), bsonDocument)); | ||
| return getBsonNumberFromNumber(result); |
Contributor
There was a problem hiding this comment.
If we need to extend $ADD and $SUBTRACT to include more operands, we can replace operands.get(0) and operands.get(1) within a loop. Not urgent now, can be done in future.
virajjasani
reviewed
Feb 3, 2026
| // 5c. document format with 2 simple operands: fieldA = fieldA + 1 = 10 + 1 = 11 | ||
| + " \"fieldA\": {\n" + " \"$ADD\": [\"fieldA\", 1]\n" + " },\n" | ||
| // 5d. document format with nested path: nested.value = nested.value + 1 = 5 + 1 = 6 | ||
| + " \"nested.value\": {\n" + " \"$ADD\": [\"nested.value\", 1]\n" + " }\n" |
Contributor
There was a problem hiding this comment.
nit: can we also add one more case where something like nested.value is top level attribute? i.e. top level attribute with .?
palashc
added a commit
to palashc/phoenix-1
that referenced
this pull request
Feb 3, 2026
…te expression (apache#2362) Co-authored-by: Palash Chauhan <p.chauhan@pchauha-ltmgv47.internal.salesforce.com>
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.
No description provided.