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 Source ID Handler #394

Open
wants to merge 11 commits into
base: v3
Choose a base branch
from
Open

Fix Source ID Handler #394

wants to merge 11 commits into from

Conversation

gunplar
Copy link
Collaborator

@gunplar gunplar commented Dec 19, 2024

No description provided.

Signed-off-by: phmai <[email protected]>
Signed-off-by: phmai <[email protected]>
Signed-off-by: phmai <[email protected]>
Signed-off-by: phmai <[email protected]>
Signed-off-by: phmai <[email protected]>
Signed-off-by: phmai <[email protected]>
@gunplar gunplar requested a review from Amaneusz December 19, 2024 15:26
Copy link

Code Coverage

Overall Project 31.23% -0.15% 🍏
Files changed 70.64% 🍏

Module Coverage
here-naksha-lib-handlers 36.99% -1.58% 🍏
Files
Module File Coverage
here-naksha-lib-handlers SourceIdHandler.java 77.24% -16.71% 🍏

Signed-off-by: phmai <[email protected]>
Copy link

Code Coverage

Overall Project 31.23% -0.15% 🍏
Files changed 70.64% 🍏

Module Coverage
here-naksha-lib-handlers 36.99% -1.58% 🍏
Files
Module File Coverage
here-naksha-lib-handlers SourceIdHandler.java 77.24% -16.71% 🍏

// PropertyOperationUtil.transformPropertyInPropertyOperationTree(
// propertyOp, SourceIdHandler::mapIntoTagOperation);
final Optional<ITagQuery> tagQuery = transformPropertyOperation(propertyOp);
if (tagQuery.isPresent()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you're using Optional you can use ifPresent with lambda so you won't need to call get afterwards :)

tagQuery.ifPresent(presentTagQuery -> {
    // ...                                   
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, I will change this place. There is 1 other place I will keep like this, as I need to access the index of the loop.

// propertyOp, SourceIdHandler::mapIntoTagOperation);
final Optional<ITagQuery> tagQuery = transformPropertyOperation(propertyOp);
if (tagQuery.isPresent()) {
readRequest.getQuery().setTags(tagQuery.get());
Copy link
Collaborator

Choose a reason for hiding this comment

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

By doing so, we will lose (override) the original tagQuery that was in ReadFeatures.
Is that intended?

If not (or we simply don't know) then we could to the following:

  1. Check if there are any tag queries in the original request
    2a) If there is a tag query, combine it via AND with tag query translated from property. We can utiliza TagAnd for that.
    2b) If there is no tag query in the original request, go with the current approach (set just translated property)

Copy link
Collaborator

Choose a reason for hiding this comment

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

But first, let's try to establish if tag query and property query can be both present here.
My intuition is that it is totally possible but TBH I did not analyze the flow

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's true, I missed this case. Yes there could be already existing tag query which should be kept. Will push the fix like you outlined.

final Optional<ITagQuery> tagQuery = transformPropertyOperation(propertyOp);
if (tagQuery.isPresent()) {
readRequest.getQuery().setTags(tagQuery.get());
if (isFullyConvertedToITagQuery(propertyOp)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like that you extracted the method for complex boolean check 👍

@@ -114,14 +125,66 @@ private Optional<String> getSourceIdFromFeature(NakshaProperties properties) {
}
}

public static Optional<ITagQuery> mapIntoTagOperation(PQuery propertyOperation) {
private static boolean isFullyConvertedToITagQuery(IPropertyQuery propertyQuery) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

A bit misleading name here IMO - we don't do anything with iTagQuery - we just check if property query is"singular"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The name makes sense only as the function is called in specific places after

final Optional<ITagQuery> tagComponent = transformPropertyOperation(propertyComponent);
if (tagComponent.isPresent())

It indicates that the property query (clause/fragment) has already been converted into tag query (clause/fragment) successfully (and in case of PAnd checking also the size to make sure nothing remains). If it's "fully converted", we can remove the property query (clause/fragment).

But I'm open to new name suggestions :b

pAnd.removeAll(toRemove);
if (tagAnd.isEmpty()) {
return Optional.empty();
} else if (tagAnd.size() == 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if these simplifications are really needed - they will happen only if the client will specify property AND with single tiem, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's for cases where a given property query PAnd is not fully transformed to tag query. Let's take the simplest example, a read features request with only this property query, no tag or other query:

(p.foo=bar && p.@ns:com:here:mom:meta.sourceId=abc)

The second clause can be converted into if tag xyz_source_id_abc exists, but the first stays the same. As we resolve this PAnd, we assume that it can possibly be converted fully into tag query, so the result is also a TagAnd. But after conversion we have a PAnd with a single component (the 1st clause unchanged) and a TagAnd with also one single component (the 2nd clause transformed).

Technically these kinds of query are allowed, but I'm not sure if the other handler components and ultimately the storages can resolve those correctly, considering these can be nested as well, like a PAnd containing only 1 PAnd containing only 1 PAnd... So we have 2 separate simplifications there, one for PAnd and one for TagAnd.

Signed-off-by: phmai <[email protected]>
Copy link

Code Coverage

Overall Project 31.23% -0.19% 🍏
Files changed 66.8% 🍏

Module Coverage
here-naksha-lib-handlers 36.95% -1.96% 🍏
Files
Module File Coverage
here-naksha-lib-handlers SourceIdHandler.java 74.6% -19.68% 🍏

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.

2 participants