-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation for findOneAndReplace command #324
Conversation
import java.util.List; | ||
|
||
/** Updates the document read from the database with the updates came as part of the request. */ | ||
public record DocumentUpdater(List<UpdateOperation> updateOperations) { | ||
public record DocumentUpdater( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tatu-at-datastax I believe extending DocumentUpdater for replace, hope this fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, makes sense wrt functionality. If we need more types in future may want to refactor.
I'll add one idea down below however.
@@ -14,6 +14,9 @@ public enum ErrorCode { | |||
|
|||
DOCUMENT_UNPARSEABLE("Unable to parse the document"), | |||
|
|||
DOCUMENT_REPLACE_DIFFERENT_DOCID( | |||
"The replace document and document resolved using filter has different _id"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has -> have
JsonNode idNode = compareDoc.remove(DocumentConstants.Fields.DOC_ID); | ||
// The replace document cannot specify an _id value that differs from the replaced document. | ||
if (replaceDocumentId != null) { | ||
if (JsonNodeComparator.ascending().compare(replaceDocumentId, idNode) != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple equality check works for kinds of JsonNode
s that are legal as doc-ids, so no need for comparator.
But maybe better is to use existing method from JsonUtil
; equalsOrdered()
? That would work even if allowed more types and is designed for equality checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Will use JsonUtil
@@ -299,4 +299,132 @@ public void invalidSetOnParentPathWithDollar() { | |||
"Update operator path conflict due to overlap: 'root' ($set) vs 'root.a' ($set)"); | |||
} | |||
} | |||
|
|||
@Nested | |||
class ReplaceDocuemntHappy { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Docuemnt -> Document
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Review comment changes
What this PR does:
Implementation for findOneAndReplace command
Which issue(s) this PR fixes:
Fixes #311
Checklist