Skip to content

Commit

Permalink
GH-159 - Fix missing labels for nodes after WITH.
Browse files Browse the repository at this point in the history
A node must be rendered completly after a `WITH` clause as long as it has not been carried forward in the body of that clause.
  • Loading branch information
michael-simons authored Mar 5, 2021
1 parent 962f363 commit af2bda4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,22 @@ void enter(With with) {

void leave(With with) {
builder.append(" ");
clearPreviouslyVisitedNamed(with);
}

private void clearPreviouslyVisitedNamed(With with) {
// We need to clear the named cache after defining a with.
// Everything not taken into the next step has to go.
// TODO This must be probably nested for subqueries, too
java.util.Set<Named> retain = new HashSet<>();
with.accept(segment -> {
if (segment instanceof SymbolicName) {
visitedNamed.stream()
.filter(named -> named.getRequiredSymbolicName().equals(segment))
.forEach(retain::add);
}
});
this.visitedNamed.retainAll(retain);
}

void enter(Delete delete) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ void mixedClausesWithWith() {

assertThat(cypherRenderer.render(statement))
.isEqualTo(
"MATCH (u:`User`)-[:`OWNS`]->(b:`Bike`) MATCH (t:`Trip`) DELETE t WITH b, t MATCH (u) WITH b, u RETURN b, u");
"MATCH (u:`User`)-[:`OWNS`]->(b:`Bike`) MATCH (t:`Trip`) DELETE t WITH b, t MATCH (u:`User`) WITH b, u RETURN b, u");
}
}

Expand Down

0 comments on commit af2bda4

Please sign in to comment.