Presence / absence of an outgoing edge from a vertex in OrientDb

妖精的绣舞 提交于 2019-12-25 01:56:16

问题


I have seen some similar questions on SO but none of the answers have worked for me yet, so I am hoping to get a new answer with the new features that have been added to recent versions of OrientDb since the other questions were asked.

I am trying to query all vertices which have an outgoing edge of a particular type but no outgoing edge of another type.

As an example in a simple relationship of

Person ---- Friend ---> Person

Person ---- Owns ---> Car

I am trying to find all the persons who have friends but do not own a car.

I have already tried the following query with no luck (It returns all the persons irrespective of whether or not those vertices have an outgoing edge of a particular kind)

select from Person where (out('Friend') not null and out('Owns').size() = 0)
select from Person where (out('Friend') is not null and out('Owns') is null)

In my efforts I realized that the NOT query is not supported yet by OrientDb in the WHERE clause as per this page: https://github.com/orientechnologies/orientdb/wiki/SQL-Where Can someone please verify if this is indeed true.

Anyways, I moved on and tried to simplify my query and tried to find only vertices that do not have the outgoing edge of 'Owns'. Even that did not work in that it seemed to return all the Person vertices in my graph:

select from Person where (out('Owns').size() = 0)
select from Person where (out('Owns') is null)

Not sure what I am missing, but any help is as always greatly appreciated.


回答1:


Try working always with size, like this:

select from Person where outE('Friend').size() > 0 and outE('Owns').size() = 0



回答2:


however, my queries return differently select from customer where outE('email').size() > 0; 0 items

select from customer where outE('email') is not NULL; many items returned

looks to me "size() > 0" is not the same as "is not NULL"

sorry if I am wrong



来源:https://stackoverflow.com/questions/22690108/presence-absence-of-an-outgoing-edge-from-a-vertex-in-orientdb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!