简体   繁体   English

OrientDB使用图进行查询分组

[英]OrientDB group by query using graph

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. 我需要在某个类的顶点的属性上执行分组聚合,但是group by字段是一个离当前节点两步的顶点,因此我无法使其工作。

My case : 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 . 我要分组的顶点是那些顶点(由B,C或D组成)中的任何一个( 如果该顶点具有defined by顶点F defined by边)

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().@rid的原因是我发现的文档指出仅支持“ =”。

out('references')[out('definedBy') contains F] doesn't work either, that returns the out('definedBy') for the $current vertex). out('references')[out('definedBy') contains F]也不起作用,返回$current顶点的out('definedBy') )。

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. 在我的示例中,我想要的结果是一列中的属性,而C顶点中的@rid是另一列。 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). 在OrientDB 2.1(我正在尝试rc4)中,有一个名为UNWIND的新子句(请参阅文档中的SELECT )。

Using UNWIND I can do: 使用UNWIND,我可以执行以下操作:

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. 根据AClass的顶点数及其引用,它可能是一个缓慢的函数,如果发现任何性能问题,我会报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM