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

Prevent OR’ing of filters containing nested paths. #799

Merged
merged 1 commit into from
Jun 4, 2020

Conversation

michael-simons
Copy link
Collaborator

A filter with nested paths will result in several matches chained together. Those matches are nessary to have the nodes holding the properties we want to filter on.

While at first it may seem trivial to think that adding a nested filter with its own match by an OR just doing an OPTIONAL MATCH, this is wrong, as the first part of the OR would need to be marked as OPTIONAL as well.

In the end trying to do so, would create very brittle Cypher statements.

Instead of, this commit improves the current checks into a single place and adds a couple of tests for it.

A query is not created when any of the filters in the chain is nested AND any other is to be chained with OR (when there is actually more than 1 filter).

This closes #796.

A filter with nested paths will result in several matches chained together. Those matches are nessary to have the nodes holding the properties we want to filter on.

While at first it may seem trivial to think that adding a nested filter with its own match by an OR just doing an OPTIONAL MATCH, this is wrong, as the first part of the OR would need to be marked as OPTIONAL as well.

In the end trying to do so, would create very brittle Cypher statements.

Instead of, this commit improves the current checks into a single place and adds a couple of tests for it.

A query is not created when any of the filters in the chain is nested AND any other is to be chained with OR (when there is actually more than 1 filter).
@codecov-commenter
Copy link

Codecov Report

Merging #799 into master will increase coverage by 0.07%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #799      +/-   ##
============================================
+ Coverage     80.33%   80.41%   +0.07%     
- Complexity     3030     3039       +9     
============================================
  Files           277      277              
  Lines          9246     9253       +7     
  Branches       1381     1381              
============================================
+ Hits           7428     7441      +13     
+ Misses         1307     1303       -4     
+ Partials        511      509       -2     
Impacted Files Coverage Δ Complexity Δ
...eo4j/ogm/session/request/FilteredQueryBuilder.java 92.68% <100.00%> (+3.79%) 28.00 <11.00> (+9.00)
...rg/neo4j/ogm/session/request/NodeQueryBuilder.java 93.58% <100.00%> (+2.23%) 22.00 <0.00> (-1.00) ⬆️
...ore/src/main/java/org/neo4j/ogm/cypher/Filter.java 92.45% <0.00%> (+1.88%) 48.00% <0.00%> (+1.00%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d8c84bb...6c57992. Read the comment docs.

@michael-simons michael-simons merged commit 0950de5 into master Jun 4, 2020
Comment on lines +49 to +57
boolean orIsPresent = StreamSupport.stream(filters.spliterator(), false)
.anyMatch(f -> BooleanOperator.OR == f.getBooleanOperator());
boolean nestedOrDeepNestedFilterPresent = StreamSupport.stream(filters.spliterator(), false)
.anyMatch(f -> f.isNested() || f.isDeepNested());

if (orIsPresent && nestedOrDeepNestedFilterPresent) {
throw new UnsupportedOperationException(
"Filters containing nested paths cannot be combined via the logical OR operator.");
}

Choose a reason for hiding this comment

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

Am I correct that this will forbid cases which are still can be supported?

michael-simons added a commit that referenced this pull request Jun 4, 2020
A filter with nested paths will result in several matches chained together. Those matches are nessary to have the nodes holding the properties we want to filter on.

While at first it may seem trivial to think that adding a nested filter with its own match by an OR just doing an OPTIONAL MATCH, this is wrong, as the first part of the OR would need to be marked as OPTIONAL as well.

In the end trying to do so, would create very brittle Cypher statements.

Instead of, this commit improves the current checks into a single place and adds a couple of tests for it.
@michael-simons michael-simons deleted the issues/796 branch August 21, 2020 13:00
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.

Nested Filter combined with OR through AND does not result in required exception.
3 participants