Search code examples
orientdb

How to select an edge from the two vertices it connects


I am trying to figure out the format for selecting an edge from the two vertexes that it connects.

The edge is in class 'Connection' and connects two 'Node' class vertices. The source node is #11:6 (UNIQUE indexed field ip = '10.64.32.100') and the destination is #11:7 (ip = '10.79.215.231'). The Connection class has a UNIQUE index on it's Connection.in and Connection.out properties.

I have tried the following queries that all return an empty set:

SELECT FROM Connection WHERE OUT(Node) = (SELECT FROM Node WHERE ip = '10.64.32.100')

SELECT FROM Connection WHERE (SELECT FROM Node WHERE ip = '10.64.32.100') IN OUT(Node)

SELECT FROM Connection WHERE #11:6 IN OUT(Node)

SELECT FROM Connection WHERE OUT(Node) = #11:6

I have checked to ensure the SELECT Node statement does infact return the correct rid (#11:6)

The larger context is updating the time field in the edge class 'Connection'. Connection has an EMBEDDEDLIST times of timestamps. Using pyorient, the calling code is:

try:
   client.command("CREATE EDGE Connection FROM {0} TO {1} CONTENT {2}".format(src_str, dst_str, edge_cont))
except pyorient.exceptions.PyOrientORecordDuplicatedException:
   client.command("UPDATE Connection ADD times = {0} WHERE {1}".format(time_list, <<!!QUERY GOES HERE!!>>)

As you can see from above, since I am using the caught exception to trigger the UPDATE, I don't have the @rid of the already existing and uniquely indexed Connection, thus I need a SELECT statement to specify which Connection object I want to add new times to. An alternate solution, would be to figure out how to return the @rid of the already existing Connection if it exists. I don't know how to do that either.

Can anyone help me find the correct SELECT statement to return the desired edge using only the two connecting vertices?


Solution

  • Try this query:

    SELECT FROM Connection WHERE OUT = #11:6 AND (SELECT @rid FROM Node WHERE ip = "10.79.215.231") IN IN

    Hope it helps.