Alberto
Alberto

Reputation: 607

OrientDB 2.1.3: traversing edges with constraints

I have detected a weird behaviour of in( ), out( ) and TRAVERSE when working with constrained edges. Given the following DB:

CREATE CLASS Employee EXTENDS V;
CREATE PROPERTY Employee.nt_account String;

CREATE CLASS ManagedBy EXTENDS E;
CREATE PROPERTY ManagedBy.out LINK Employee;
CREATE PROPERTY ManagedBy.In LINK Employee;

CREATE INDEX Employee.nt_account unique_hash_index;

CREATE VERTEX Employee SET nt_account = 'e0';
CREATE VERTEX Employee SET nt_account = 'e1';
CREATE VERTEX Employee SET nt_account = 'e2';

CREATE EDGE ManagedBy FROM (SELECT FROM Employee WHERE nt_account = 'e0') TO (SELECT FROM Employee WHERE nt_account = 'e1');
CREATE EDGE ManagedBy FROM (SELECT FROM Employee WHERE nt_account = 'e1') TO (SELECT FROM Employee WHERE nt_account = 'e2');
CREATE EDGE ManagedBy FROM (SELECT FROM Employee WHERE nt_account = 'e2') TO (SELECT FROM Employee WHERE nt_account = 'e0');

Running a query similar to the one found in this answer:

TRAVERSE out('ManagedBy') FROM (SELECT FROM Employee where nt_account = 'e0')

returns only one record: the entry of e0. The problem persists if I substitute the SELECT subquery with e0's RID. Similar things happen when selecting out('ManagedBy'). Interestingly, the same queries in a database with the same structure but without the constraints on ManagedBy return the right result.

Does anybody know what's wrong with my code? (or, have I found a bug?)

Moreover, does anybody know how I can write an OSQL query that detects loops in a graph? In Cypher I would write

MATCH p=(e: Employee)-[:MANAGED_BY*]->(e)
RETURN p

I got good advice for the first part of the question both from @wolf4ood and @LucaS. I marked the first answer as correct (FCFS) but I think the second one too works. As for the query, I solved it myself:

SELECT out.nt_account, shortestPath(in, out, 'OUT').nt_account 
FROM ManagedBy

As trivial as it can seem, it took me a while to write it. The trick I used is to iterate directly on the edges and check if there is a shortest path exiting from the target node and going to the source node.

Upvotes: 1

Views: 152

Answers (2)

LucaS
LucaS

Reputation: 1418

I tried your DB and out() doesn't work, but in() yes instead. I declared 'ManagedBy.out' with the "O" uppercase and now 'out()' works.

CREATE PROPERTY ManagedBy.Out LINK Employee

enter image description here

Upvotes: 2

wolf4ood
wolf4ood

Reputation: 1949

By default properties are case sensitive

http://orientdb.com/docs/2.1/SQL-Alter-Property.html

you create in property as In

CREATE PROPERTY ManagedBy.In LINK Employee;

the traverse command is expecting an in property. So the traversing process return only the starting node.

Change this statement in

CREATE PROPERTY ManagedBy.in LINK Employee;

and it will work

Upvotes: 2

Related Questions