OrientDB组通过使用图形进行查询 [英] OrientDB group by query using graph

查看:435
本文介绍了OrientDB组通过使用图形进行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对某个类的顶点属性执行分组聚合,然而,group by字段是距离当前节点两步的顶点,我无法使其工作。



我的情况
顶点A包含我想要聚合的属性,并且有 n 引用。如果顶点具有由边界定义的到顶点F ,那么我想要分组的顶点是这些顶点(B,C或D) 。

  A ----引用 - > B  - 由 - >定义E 
\ ---参考文献 - > C - 由 - >定义F
\ - 参考文献 - > D - 由 - >定义G
...

我认为可以使用的查询是:

  select sum(property),groupOn from(
select property,out('references')[out('definedBy')。@ rid = F] as groupOn from AClass
)group by groupOn

但它没有工作,内部声明给了我一个奇怪的回应,这是不正确的(不返回顶点),我怀疑 out()不支持括号条件(原因对于。@ rid 是我发现的文档声明只支持=。



out('references')[out('definedBy')contains F] 也不起作用,返回 out('definedBy')用于 $ current 顶点)。

任何人有想法如何实现这个?在我的例子中,我想要的结果是一列中的属性和另一列中的C顶点的@rid。然后,我可以愉快地执行我的小组。聚合。

解决方案

解决它!在OrientDB 2.1中(我正在尝试rc4),有一个叫做 UNWIND 的新子句(参见 SELECT )。

使用UNWIND我可以这样做:

  SELECT sum(property),groupOn from(
SELECT property,out('references')as groupOn
FROM AClass
UNWIND groupOn
)WHERE groupOn.out('definedBy')= F
GROUP BY groupOn

它可能是一个缓慢的函数,取决于AClass的顶点数及其引用,如果我发现任何性能问题,我会报告回来。


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.

My case: The vertex A contains the property I want to aggregate on and have n number of vertices with label 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.

这篇关于OrientDB组通过使用图形进行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆