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

Fix #71: implement $inc update operator #83

Merged
merged 9 commits into from
Feb 9, 2023

Conversation

tatu-at-datastax
Copy link
Contributor

@tatu-at-datastax tatu-at-datastax commented Feb 7, 2023

Implements $inc update operator, adds unit and integration tests for the same (and one IT for "$push" that was missing).

@tatu-at-datastax tatu-at-datastax self-assigned this Feb 7, 2023
@tatu-at-datastax tatu-at-datastax changed the title (WIP) Fix #71: implement $inc update operator Fix #71: implement $inc update operator Feb 7, 2023
@tatu-at-datastax tatu-at-datastax marked this pull request as ready for review February 7, 2023 23:13
@tatu-at-datastax tatu-at-datastax requested a review from a team as a code owner February 7, 2023 23:13
@tatu-at-datastax tatu-at-datastax linked an issue Feb 7, 2023 that may be closed by this pull request
Copy link
Contributor

@ivansenic ivansenic left a comment

Choose a reason for hiding this comment

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

Looks pritty good.. Added some comments and suggestions..

/**
* Implementation of {@code $inc} update operation used to modify numeric field values in documents.
*/
public class IncOperation extends UpdateOperation {
Copy link
Contributor

Choose a reason for hiding this comment

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

So now we have two types of operations? The ones that are in the the commands, and then operations that execute the queries. Can we find another name to avoid confusion (because I was just like wtf is going on)

@maheshrajamani @amorton

Copy link
Contributor

Choose a reason for hiding this comment

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

My suggestion is to change the ones extending Operation interface as Executors (Eg: FindOperation -> FindExecutor). The ones in FilterClause and UpdateClause to be left as is. @amorton thoughts?

Copy link
Contributor Author

@tatu-at-datastax tatu-at-datastax Feb 9, 2023

Choose a reason for hiding this comment

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

I could also change Operation part to Operator to have IncOperator etc (and renaming UpdateOperator enum) if that would help. But I like @maheshrajamani 's suggestion.

Comment on lines 156 to 158
"""
{ "integer" : 1, "fp" : 0.25, "text" : "value" }
""");
Copy link
Contributor

Choose a reason for hiding this comment

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

tab spacing?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's so hard to understand the test when in every method I need to scroll down here to see what's the test setup.. Would you inline this in every test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmh. I guess it's matter of taste really; duplication vs extraction. But I guess for this particular case content is small enough I could inline.

Indentation is due to IDE and mvn fmt:format which is bit odd but hard to control. :-/

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea indentation needs some manual work as this formatting model does not support it.. Btw this formatting model is terrible..

{
"updateOne": {
"filter" : {"_id" : "update_doc_inc"},
"update" : {"$inc" : {"number": -4 }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be great to test $inc on multiple fields, and $inc on a field that doesn't already exist.

Also, would it be difficult to handle dotted paths with $inc? I don't think that's necessary for first release, but worth thinking about.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vkarpov15 Unit tests below handle many more cases: Integration test only tests subset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, would it be difficult to handle dotted paths with $inc? I don't think that's necessary for first release, but worth thinking about.

Yes, there is separate issue for dotted path support: I hope to support it similar way for all update operations.
And it's definitely high priority.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added unit test for trying to $inc an explicit null; caught as expected.

/**
* Implementation of {@code $inc} update operation used to modify numeric field values in documents.
*/
public class IncOperation extends UpdateOperation {
Copy link
Contributor

Choose a reason for hiding this comment

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

My suggestion is to change the ones extending Operation interface as Executors (Eg: FindOperation -> FindExecutor). The ones in FilterClause and UpdateClause to be left as is. @amorton thoughts?

@tatu-at-datastax tatu-at-datastax merged commit 6177870 into main Feb 9, 2023
@tatu-at-datastax tatu-at-datastax deleted the tatu/71-add-update-oper-inc branch February 9, 2023 20:30
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 "$inc" update operator
4 participants