Skip to content
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

Merged
merged 7 commits into from
Mar 30, 2023
Merged

Conversation

maheshrajamani
Copy link
Contributor

@maheshrajamani maheshrajamani commented Mar 30, 2023

What this PR does:
Implementation for findOneAndReplace command
Which issue(s) this PR fixes:
Fixes #311

Checklist

  • Changes manually tested
  • Automated Tests added/updated
  • Documentation added/updated
  • CLA Signed: DataStax CLA

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(
Copy link
Contributor Author

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.

Copy link
Contributor

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.

@maheshrajamani maheshrajamani marked this pull request as ready for review March 30, 2023 22:33
@maheshrajamani maheshrajamani requested a review from a team as a code owner March 30, 2023 22:33
@@ -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"),
Copy link
Contributor

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) {
Copy link
Contributor

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 JsonNodes 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.

Copy link
Contributor Author

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Docuemnt -> Document

Copy link
Contributor

@tatu-at-datastax tatu-at-datastax left a 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
@maheshrajamani maheshrajamani merged commit acc2ef2 into main Mar 30, 2023
@maheshrajamani maheshrajamani deleted the findOneAndReplace branch March 30, 2023 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement findOneAndReplace command
2 participants