Using OrientDB's query language, how can find all vertices in cluster a
that have no outgoing edge ending in a vertex of class b
(i.e. no direct neighbour vertex of class b
)?
It does not matter if they have other outgoing edges.
Asked
Active
Viewed 1,755 times
6

Thilo
- 257,207
- 101
- 511
- 656
1 Answers
3
If you've a class A mapped to cluster a you can do:
select from A where not( out.in.@class in ['b'] )
That means cross the "out" property of A records (as edges), then the "in" property (the vertex) and then get the class name (@class). I've used the IN operator instead of = (equals) because "out.in.@class" returns a collection of class names.
If you want have no A class and you have to go through the cluster A use cluster: syntax:
select from cluster:A where not( out.in.@class in ['b'] )
I've tested against latest 1.0rc8-SNAPSHOT and works.

Lvca
- 8,938
- 2
- 24
- 25
-
Is that really the syntax? There is no difference between the two cases. I cannot get it to work (on rc7). I get `unknown function "not"`. Does the double quote at the end need to be matched? – Thilo Jan 15 '12 at 03:00
-
Works only with 1.0rc8-SNAPSHOT – Lvca Jan 16 '12 at 16:45
-
Okay, will check after it's released. Any way to do it with an earlier version? And what is the meaning of the double quote at the end? – Thilo Jan 16 '12 at 23:47
-
Sorry for " it comes from cut & paste. With previous release there is no way to do it in one shot unless you use GREMLIN function (use the Graph(ed) distribution) like "SELECT FROM GREMLIN(
) FROM A". More on gremlin expressions: https://github.com/tinkerpop/gremlin/wiki – Lvca Jan 19 '12 at 19:03 -
Okay, last question, then you get your +1 ;-) : What is the difference between the cluster-syntax query and the first one? They look exactly the same? – Thilo Jan 20 '12 at 00:31
-
Class is a higher level concept than cluster (http://code.google.com/p/orient/wiki/Concepts#Cluster) taken from Object Orientation. When you create a class you can define in what cluster(s) record will go. By default there is 1 cluster per class with the same name, so in your case it's pretty the same. But you could create a class Employee that stores record on employee2011 and employee2012 clusters. This allow to query all the employee using the class or filter by year using the cluster. – Lvca Jan 20 '12 at 10:24
-
You could also filter per year using a filter in SQL select if you declare a "year" field (select from employee where year = 2012), but this is much more efficient because avoid scanning of all the clusters but just the right one. The combination Class/Cluster is very powerful and allows to resolve many use cases. – Lvca Jan 20 '12 at 10:25
-
I've create this section in WiKi: http://code.google.com/p/orient/wiki/Concepts#Class. Hope it helps. – Lvca Jan 20 '12 at 10:59
-
so the second query in your answer should have been `select from cluster:a where not( out.in.@class in ['b'] )`? – Thilo Jan 20 '12 at 12:43
-
Yes, fixed in the answer above – Lvca Apr 12 '12 at 00:41