Search code examples
orientdborient-sql

OrientDB Include property from edge connected to specific vertex


I have the following case:

       (p:p1)
  V1 ---E1---\ 
              \
               V2 (with properties)
              /
  V1 ---E1---/
       (p:p2)

So two vertices of class V1 are connected to another Vertex of type V2, both edges are of the same class E1 which has the property "p".

I would like a query that:

  • Targets a V1 instance (by rid)
  • Reads all V2 records (including all properties) that are connected to the selected V1 by the edge class E1
  • Also includes the property p from the connecting E1-edge in the returned documents.

I have tried with:

SELECT *,in('E1')[p] as p FROM (SELECT EXPAND(out('E1')) FROM <V1-rid>) UNWIND p

But that would of course give 2 results since the projection returns values from both the E1 edges. I only want to inlcude p form the edge between my selected V1 and V2.

I have some other connections to V2 as well which need to be included, but I wanted to specify the problem more precise to reduce the question complexity and I think (hope) they won't interfere with the answer.

Update

Clarification:

I would like the result to be whole V2-records with appended properties "p", so if V2 has properties v2p1:, v2p2, the resulting records should look something like:

{
   "v2p1": <value>,
   "v2p2": <value>,
   "p": <value>
}

Where the last "p" value is from the edge and the other properties are from the actual V2 records.


Solution

  • try this:

    select *,traversedEdge(-1).p as p from(traverse outE('E1'),inV('E1') from #21:0) where @class='V2'