I need to perform an grouped aggregate on a property of vertices of a certain class, the group by field is however a vertex two steps away from my current node and I can't make it work.
: The vertex A contains the property I want to aggregate on and have n number of vertices with label references
. :顶点A包含我要在其上聚合的属性,并且具有n个带有标签references
的顶点。 The vertex I want to group on is any of those vertices (B, C or D) if that vertex has a defined by
edge to vertex F .
A ----references--> B --defined by--> E
\---references--> C --defined by--> F
\--references--> D --defined by--> G
...
The query I thought would work is:
select sum(property), groupOn from (
select property, out('references')[out('definedBy').@rid = F] as groupOn from AClass
) group by groupOn
But it doesn't work, the inner statement gives me a strange response which isn't correct (returns no vertices) and I suspect that out()
isn't supported for bracket conditions (the reason for the .@rid
is that the docs I found stated that only "=" are supported.
out('references')[out('definedBy') contains F]
doesn't work either, that returns the out('definedBy')
for the $current
vertex).
Anyone with an idea how to achieve this? In my example, the result I would like is the property in one column and the @rid of the C vertex in another. Then I can happily perform my group by aggregates.
Solved it! In OrientDB 2.1 (I'm trying rc4) there's a new clause called UNWIND
(see SELECT in docs).
Using UNWIND I can do:
SELECT sum(property), groupOn from (
SELECT property, out('references') as groupOn
FROM AClass
UNWIND groupOn
) WHERE groupOn.out('definedBy')=F
GROUP BY groupOn
It could potentially be a slow function depending on the number of vertices of AClass and its references, I'll report back if I find any performance issues.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.