Search code examples
orientdb

OrientDB: Select unique vertices but retain the edges


I am trying to do the following weird thing. I have a group of edges that point towards a group of vertices, but there is some repetition - multiple edges point to the same vertices.

Given a SELECT command that gives me the list of edges, I want to:

  • SELECT the unique vertices from all of the 'out' vertices
  • Return, along with the @rid of the unique vertices, a list of all the edges that pointed towards them.

E.g. the result should be a list of vertices with (vertex rid, [edge 1, edge 2, edge 3]).

Another way to think about this is I want to GROUP BY outgoing vertex but somehow retain in a field the @rid's of all the edges I grouped.

Thanks!


Solution

  • You can try this:

    in this you get for every vertex the outgoing edges

    select $a.@rid, $a.outE() from 'your class'
    let $a = (select from 'your class' where $parent.current.@rid = @rid)
    

    if you want the ingoing vertices you have to change $a.outE() with inE(), like below:

    select $a.@rid, $a.inE() from 'your class'
    let $a = (select from 'your class' where $parent.current.@rid = @rid)
    

    Hope it helps.

    Regards.