Given two edges, e1 and e2, I would like to know if there is a way in GSQL of getting its intersection and then check if it exists in the graph. For example:
e1 = (1, 2)
e2 = (2, 3)
Then the intersection would be the edge (1, 3), which is an edge I would like to know if it exists in the graph.
This code should fulfill your request. It would be much easier to do in GSQL Syntax v2, but I was running into cryptic error messages that I could not get around.
Thus, here it is in Syntax v1, which will actually run more efficiently than a Syntax v2 implementation:
// Variables
EDGE answer;
SetAccum<VERTEX> @@starting;
start = {ANY};
// @@starting should have 2 possible start vertices
hop1 = SELECT t FROM start:s - (:e) - :t
WHERE e == e1
POST-ACCUM @@starting += s;
// Now @@starting contains the only actual starting vertex
// (Not the one shared by both e1 and e2)
hop2 = SELECT t FROM hop1:s - (:e) - :t
WHERE e == e2
POST-ACCUM @@starting.remove(s);
// Check if starting and ending vertices can be connected with 1 hop
checkIntersection = SELECT t FROM hop2:s - (:e) - :t
WHERE @@starting.contains(t)
ACCUM answer = e;
PRINT answer;
1 Like