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

Implement $eq support for sub document #98

Merged
merged 13 commits into from
Feb 10, 2023
Merged

Implement $eq support for sub document #98

merged 13 commits into from
Feb 10, 2023

Conversation

maheshrajamani
Copy link
Contributor

Fix for #96

sub_doc_equals field in table changed to
# Conflicts:
#	src/main/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/FindOperation.java
#	src/main/java/io/stargate/sgv2/jsonapi/service/resolver/model/impl/matcher/FilterableResolver.java
#	src/main/java/io/stargate/sgv2/jsonapi/service/shredding/model/DocValueHasher.java
#	src/test/java/io/stargate/sgv2/jsonapi/service/operation/model/impl/FindOperationTest.java
#	src/test/java/io/stargate/sgv2/jsonapi/service/shredding/model/DocValueHasherTest.java
@maheshrajamani maheshrajamani marked this pull request as ready for review February 10, 2023 17:12
@maheshrajamani maheshrajamani requested a review from a team as a code owner February 10, 2023 17:12
@@ -93,6 +93,28 @@ public void setUp() {
.post(CollectionResource.BASE_PATH, keyspaceId.asInternal(), collectionName)
.then()
.statusCode(200);

json =
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, my changes will conflict here (sorry!)

assertThat(hash).isNotNull();
Map<String, Object> values = new LinkedHashMap<>();
values.put("a1", new BigDecimal(5));
Map<String, Object> innerValues = new LinkedHashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

One idea: would be good to verify that innerValues hash is also identical to equivalent sub-tree (ObjectNode of document at JsonPointer.compile("/b1").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how to do this the hash method calls in recursive.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can just get JsonNode out of document (document.get("b1")), calculate it separately.
And calculate similarly for innerValues.

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.

Looks good: added some suggestions and one question on exception.

sub_doc_equals field in table changed to
Rebased to main
# Conflicts:
#	src/test/java/io/stargate/sgv2/jsonapi/api/v1/FindIntegrationTest.java
sub_doc_equals field in table changed to
Rebased to main
# Conflicts:
#	src/test/java/io/stargate/sgv2/jsonapi/api/v1/FindIntegrationTest.java
… sub_doc_eq

# Conflicts:
#	src/main/java/io/stargate/sgv2/jsonapi/service/shredding/model/DocValueHasher.java
#	src/test/java/io/stargate/sgv2/jsonapi/api/v1/FindIntegrationTest.java
@maheshrajamani
Copy link
Contributor Author

Not sure why it shows the changes from merged code when i did a rebase

@maheshrajamani maheshrajamani merged commit 75514ec into main Feb 10, 2023
@maheshrajamani maheshrajamani deleted the sub_doc_eq branch February 10, 2023 19:21
@@ -412,24 +557,101 @@ public void findWithSizeOperatorNoMatch() {
.post(CollectionResource.BASE_PATH, keyspaceId.asInternal(), collectionName)
.then()
.statusCode(200)
.body("data.count", is(0));
.body("data.count", is(1))
.body("data.docs[0]", jsonEquals(expected));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great that this works! Small question though: what about key order? If I swap key order by changing { "c": "v1", "d": false } to { "d": false, "c": "v1" } would I still get a result?

Copy link
Contributor Author

@maheshrajamani maheshrajamani Feb 13, 2023

Choose a reason for hiding this comment

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

@vkarpov15 The key order has to be same to return result. Do we need to make it work for any order?

Copy link
Contributor

Choose a reason for hiding this comment

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

@maheshrajamani As far as I know, MongoDB retains and checks field order so filter must match that too. From that I think the suggestion is that maybe there should be negative test to ensure different ordering does NOT match the row?

Another minor point: jsonEquals() probably does order-insensitive comparison (at least Jackson JsonNode is order-insensitive and most JSON packages are similarly). I think this is fine for most tests but good to keep in mind for small number where we do want to check that order is retained. I think it's fine here too since the focus is not on ensuring storage of doc, retaining.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@tatu-at-datastax is right, key order matters for filtering. If you swap key order and change { "c": "v1", "d": false } to { "d": false, "c": "v1" } you should not get a result in this test. Would be nice to add a test case for checking key order just in case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add a test case for this

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.

3 participants