Reverse EDGE traversal

I have an EDGE “Transfer_Money” from Vertex A to A as A->A. this is directed edge but has no reverse edge.

I know I can traverse it below.

Start = Select s

From Start:s-(Transfer_Money:e)->A:tgt;

Can I also do the other way around ? like

Start = Select s

From  **Start:s<-(Transfer_Money:e)-A:tgt;**

This is my requirement because i need to take count of who a person has received money from. I need to count total person who has sent money to that particular person.

Thanks

Hanif

It is very hard to do this without a reverse edge.

Since for a directed edge, the source vertex is not visible from the target vertex. E.g. in case of A1->A2, A2 cannot access to A1.

The only way I can think of is to start from all senders, traverse to the receiver, then keep the particular person in the result set.

This is very expensive and unlikely to be real-time.

Therefore it is highly recommended to create a reverse edge in your use case.

Thanks.

Thank you Chang.

Can you show me through code what I should be doing>

Please refer this doc on how to create a reverse edge.

In GraphStudio, just check the reverse edge checkbox when you define the edge.

Once it is defined and published. You can use the edge type, reverse_Transfer_Money to get the receiving relationship in a reversed direction.

Chang,

I have a schema like below. It also has reverse edge as “reverse_Transfer_Money”.

pic-1

I want to see all those person who has received money from more than 5 person. I wanted to visualize the output like below.

pic-2

but all I can see is below which is not correct since all the arrows are pointing out towards the persons who has transferred money to the one in the middle. it should be the other way around.

pic-3

I would like to see is the output in pic-2. Below is the query if you can help me correct it.

CREATE QUERY AbnormalTransaction() FOR GRAPH MyGraph {

SumAccum<INT> @count = 0;
SetAccum<edge> @evidence, @@edgeSet;
SetAccum<vertex> @@verSet;
Start = {Account.*};

Start = SELECT s
FROM Start:s-(reverse_Transfers_Money:e)-Account:tgt
ACCUM s.@evidence += e,
s.@count += 1;

Start = SELECT s from Start:s
where s.@count >5
ACCUM @@edgeSet += s.@evidence;

PRINT @@edgeSet;

}

Just to confirm you’re only wanting to have the query in TigerGraph Studio give you the visual in picture 2? You’re query appears to be identifying everything correctly and you have ways to glean the related information from it through reverse edges.

However if you just want to have the second visual returned I believe the following should work

SumAccum<INT> @count = 0;
SetAccum<edge> @evidence, @@edgeSet;
SetAccum<vertex> @@verSet;

Start = {Account.*};

suspiciousAccounts = SELECT s
FROM Start:s-(reverse_Transfers_Money:e)-Account:tgt
ACCUM s.@evidence += e,
s.@count += 1
POST-ACCUM
IF s.@count > 5 THEN
@@verSet += s
END;

Start = SELECT s FROM Start:s-(Transfers_Money:e)->Account:tgt
WHERE tgt IN @@verSet
ACCUM @@edgeSet += e;
PRINT @@edgeSet;

Thank you very much Ric. This is exactly what I wanted to achieve.

Hi , How do i do this traversal , if i want to traverse all kinds of reverse edges.
I have multiple types of edges

@arpan An edge traversal is the same forward as it is back. You just need to specify the edge you would like to traverse in your query. If you have an undirectional edge you can go back and forth on the same edge name. If you have a directional edge you won’t be able to traverse in reverse unless you created a reverse edge during your schema design.

Thanks , I was able to do this.

1 Like