Skip to content

Commit

Permalink
GH113 - Allow conditions based on path patterns on pattern comprehens…
Browse files Browse the repository at this point in the history
…ions.
  • Loading branch information
michael-simons committed Dec 4, 2020
1 parent bd59e5f commit e73afaa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ public interface OngoingDefinitionWithPattern extends OngoingDefinitionWithoutRe
* @return An ongoing definition of a pattern comprehension for furhter modification
*/
OngoingDefinitionWithPatternAndWhere where(Condition condition);

/**
* Adds a where clause based on a path pattern to the ongoing definition
*
* @param pathPattern The path pattern to add to the where clause.
* This path pattern must not be {@literal null} and must
* not introduce new variables not available in the match.
* @return A match or a call restricted by a where clause with no return items yet.
* @since 2020.1.4
*/
default OngoingDefinitionWithPatternAndWhere where(RelationshipPattern pathPattern) {

Assertions.notNull(pathPattern, "The path pattern must not be null.");
return this.where(new RelationshipPatternCondition(pathPattern));
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,22 @@ void doc3653() {
.isEqualTo("MATCH (n:`Person`) WHERE (n)-[:`KNOWS`]-( {name: 'Timothy'}) RETURN n.name, n.age");
}

@Test
void gh113() {

Node foo = Cypher.node("Foo").named("foo");
Node bar = Cypher.node("Bar").named("bar");
Relationship fooBar = foo.relationshipTo(bar, "FOOBAR").named("rel");
PatternComprehension pc = Cypher.listBasedOn(fooBar)
.where(bar.relationshipTo(Cypher.node("ZZZ"), "HAS"))
.returning(fooBar, bar);
Statement statement = Cypher.match(foo).returning(foo.getRequiredSymbolicName(), pc).build();

assertThat(cypherRenderer.render(statement)).isEqualTo(
"MATCH (foo:`Foo`) RETURN foo, [(foo)-[rel:`FOOBAR`]->(bar:`Bar`) WHERE (bar)-[:`HAS`]->(:`ZZZ`) | [rel, bar]]"
);
}

@Test
void doc3654() {

Expand Down

0 comments on commit e73afaa

Please sign in to comment.