diff --git a/engine/src/main/java/com/arcadedb/query/opencypher/executor/steps/CreateStep.java b/engine/src/main/java/com/arcadedb/query/opencypher/executor/steps/CreateStep.java index 4776f89821..8881219aa9 100644 --- a/engine/src/main/java/com/arcadedb/query/opencypher/executor/steps/CreateStep.java +++ b/engine/src/main/java/com/arcadedb/query/opencypher/executor/steps/CreateStep.java @@ -31,6 +31,7 @@ import com.arcadedb.query.opencypher.ast.NodePattern; import com.arcadedb.query.opencypher.ast.PathPattern; import com.arcadedb.query.opencypher.ast.RelationshipPattern; +import com.arcadedb.query.opencypher.ast.Direction; import com.arcadedb.query.opencypher.parser.CypherASTBuilder; import com.arcadedb.query.sql.executor.*; @@ -205,8 +206,16 @@ private void createPath(final PathPattern pathPattern, final ResultInternal resu // Create relationships between vertices for (int i = 0; i < pathPattern.getRelationshipCount(); i++) { final RelationshipPattern relPattern = pathPattern.getRelationship(i); - final Vertex fromVertex = vertices.get(i); - final Vertex toVertex = vertices.get(i + 1); + final Vertex fromVertex; + final Vertex toVertex; + + if (relPattern.getDirection() == Direction.IN) { + fromVertex = vertices.get(i + 1); + toVertex = vertices.get(i); + } else { + fromVertex = vertices.get(i); + toVertex = vertices.get(i + 1); + } final Edge edge = createEdge(fromVertex, toVertex, relPattern, result); if (relPattern.getVariable() != null) { diff --git a/engine/src/main/java/com/arcadedb/query/opencypher/executor/steps/MergeStep.java b/engine/src/main/java/com/arcadedb/query/opencypher/executor/steps/MergeStep.java index a23cc72c0a..489fb8b404 100644 --- a/engine/src/main/java/com/arcadedb/query/opencypher/executor/steps/MergeStep.java +++ b/engine/src/main/java/com/arcadedb/query/opencypher/executor/steps/MergeStep.java @@ -31,6 +31,7 @@ import com.arcadedb.query.opencypher.ast.NodePattern; import com.arcadedb.query.opencypher.ast.PathPattern; import com.arcadedb.query.opencypher.ast.RelationshipPattern; +import com.arcadedb.query.opencypher.ast.Direction; import com.arcadedb.query.opencypher.ast.SetClause; import com.arcadedb.query.opencypher.executor.CypherFunctionFactory; import com.arcadedb.query.opencypher.executor.ExpressionEvaluator; @@ -278,8 +279,16 @@ private boolean mergePath(final PathPattern pathPattern, final ResultInternal re // Merge relationships between vertices for (int i = 0; i < pathPattern.getRelationshipCount(); i++) { final RelationshipPattern relPattern = pathPattern.getRelationship(i); - final Vertex fromVertex = vertices.get(i); - final Vertex toVertex = vertices.get(i + 1); + final Vertex fromVertex; + final Vertex toVertex; + + if (relPattern.getDirection() == Direction.IN) { + fromVertex = vertices.get(i + 1); + toVertex = vertices.get(i); + } else { + fromVertex = vertices.get(i); + toVertex = vertices.get(i + 1); + } // Try to find existing relationship Edge edge = findEdge(fromVertex, toVertex, relPattern, result);