Regarding join in pyspark Given a rdd in pyspark, $A=[(0, 1), (1, 2), (1, 3), (3, 0)]$  


I am trying to find self join of A such that the second element of previous pair is equal to first element of next pair i.e.    

$result=[(0, 2), (0, 3), (1, 0)]$

I tried taking cartesian but it is giving other possibilities.
Also I tried with reverse of the above and then joining but it is also giving many use cases.
Please let me know the correct approach to solve the above.
I got the answer by taking reverse of the above list and then using inner join of rdd to get all corresponding transitive pairs. After removing duplicates i.e. (b,a) and same edges (a,a) or (b,b) got the resulting rdd.

Thanks for the help.