Skip to content

Commit 0fd7142

Browse files
ExtReMLapinCNE Pierre FICHEPOIL
andauthored
Fix relation direction creation with merge and create, fixes #3326 (#3353)
Co-authored-by: CNE Pierre FICHEPOIL <[email protected]>
1 parent d6cbc10 commit 0fd7142

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

engine/src/main/java/com/arcadedb/query/opencypher/executor/steps/CreateStep.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.arcadedb.query.opencypher.ast.NodePattern;
3232
import com.arcadedb.query.opencypher.ast.PathPattern;
3333
import com.arcadedb.query.opencypher.ast.RelationshipPattern;
34+
import com.arcadedb.query.opencypher.ast.Direction;
3435
import com.arcadedb.query.opencypher.parser.CypherASTBuilder;
3536
import com.arcadedb.query.sql.executor.*;
3637

@@ -205,8 +206,16 @@ private void createPath(final PathPattern pathPattern, final ResultInternal resu
205206
// Create relationships between vertices
206207
for (int i = 0; i < pathPattern.getRelationshipCount(); i++) {
207208
final RelationshipPattern relPattern = pathPattern.getRelationship(i);
208-
final Vertex fromVertex = vertices.get(i);
209-
final Vertex toVertex = vertices.get(i + 1);
209+
final Vertex fromVertex;
210+
final Vertex toVertex;
211+
212+
if (relPattern.getDirection() == Direction.IN) {
213+
fromVertex = vertices.get(i + 1);
214+
toVertex = vertices.get(i);
215+
} else {
216+
fromVertex = vertices.get(i);
217+
toVertex = vertices.get(i + 1);
218+
}
210219

211220
final Edge edge = createEdge(fromVertex, toVertex, relPattern, result);
212221
if (relPattern.getVariable() != null) {

engine/src/main/java/com/arcadedb/query/opencypher/executor/steps/MergeStep.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.arcadedb.query.opencypher.ast.NodePattern;
3232
import com.arcadedb.query.opencypher.ast.PathPattern;
3333
import com.arcadedb.query.opencypher.ast.RelationshipPattern;
34+
import com.arcadedb.query.opencypher.ast.Direction;
3435
import com.arcadedb.query.opencypher.ast.SetClause;
3536
import com.arcadedb.query.opencypher.executor.CypherFunctionFactory;
3637
import com.arcadedb.query.opencypher.executor.ExpressionEvaluator;
@@ -278,8 +279,16 @@ private boolean mergePath(final PathPattern pathPattern, final ResultInternal re
278279
// Merge relationships between vertices
279280
for (int i = 0; i < pathPattern.getRelationshipCount(); i++) {
280281
final RelationshipPattern relPattern = pathPattern.getRelationship(i);
281-
final Vertex fromVertex = vertices.get(i);
282-
final Vertex toVertex = vertices.get(i + 1);
282+
final Vertex fromVertex;
283+
final Vertex toVertex;
284+
285+
if (relPattern.getDirection() == Direction.IN) {
286+
fromVertex = vertices.get(i + 1);
287+
toVertex = vertices.get(i);
288+
} else {
289+
fromVertex = vertices.get(i);
290+
toVertex = vertices.get(i + 1);
291+
}
283292

284293
// Try to find existing relationship
285294
Edge edge = findEdge(fromVertex, toVertex, relPattern, result);

0 commit comments

Comments
 (0)