Skip to content

Commit

Permalink
Delete improvements (#151)
Browse files Browse the repository at this point in the history
Signed-off-by: Dwitry <dwitry@users.noreply.github.com>
  • Loading branch information
dwitry committed Aug 2, 2018
1 parent 54557e2 commit b1f0c9a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,26 @@ public void deleteOnNullNode() throws Exception {
assertThat(onDelete)
.isEmpty();
}

@Test
public void deleteConnectedNodeAndRelationship() {
List<Map<String, Object>> beforeDelete = submitAndGet(
"MATCH (n) RETURN count(*)"
);
List<Map<String, Object>> onDelete = submitAndGet(
"MATCH (s:software {name: 'ripple'})<-[r:created]-(p:person) DELETE s, r"
);
List<Map<String, Object>> afterDelete = submitAndGet(
"MATCH (n) RETURN count(*)"
);

assertThat(beforeDelete)
.extracting("count(*)")
.containsExactly(6L);
assertThat(onDelete)
.isEmpty();
assertThat(afterDelete)
.extracting("count(*)")
.containsExactly(5L);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ class DeleteWalker[T, P](context: WalkerContext[T, P], g: GremlinSteps[T, P]) {

def walkClause(node: Delete): Unit = {
val Delete(expressions, detach) = node
val edgesFirst = expressions.sortBy(e =>
context.expressionTypes.get(e) match {
case Some(_: RelationshipType) => false
case _ => true
})

val sideEffect = g.start()
expressions.foreach(safeDelete(sideEffect, _, detach))

g.barrier().sideEffect(sideEffect)
g.barrier()
edgesFirst.foreach(safeDelete(g, _, detach))
}

private def safeDelete(
Expand All @@ -48,18 +51,18 @@ class DeleteWalker[T, P](context: WalkerContext[T, P], g: GremlinSteps[T, P]) {
val expressionTraversal = ExpressionWalker.walkLocal(context, g, expr)
val typ = context.expressionTypes.get(expr)

expressionTraversal.is(p.neq(Tokens.NULL))

if (!checkBeforeDelete) {
typ match {
case Some(_: NodeType) =>
expressionTraversal.sideEffect(
g.start()
.is(p.neq(Tokens.NULL))
.bothE()
.constant(DELETE_CONNECTED_NODE.toString)
.map(CustomFunction.cypherException())
)
case Some(_: RelationshipType) =>
case _ =>
case _ =>
}
}

Expand All @@ -72,6 +75,6 @@ class DeleteWalker[T, P](context: WalkerContext[T, P], g: GremlinSteps[T, P]) {
case _ =>
}

subTraversal.sideEffect(expressionTraversal.is(p.neq(Tokens.NULL)).drop())
subTraversal.sideEffect(expressionTraversal.drop())
}
}

0 comments on commit b1f0c9a

Please sign in to comment.