2016-04-04 25 views
0

我使用OrientDB的Java嵌入式版本,我想執行一些gremlin查詢。 所以我使用GremlinPipeline來做到這一點。 我想知道如何做一個小組。GroupBy使用GremlinPipeline與OrientDB

說每個頂點包含一個屬性「年齡」,我想在這個屬性上做一個組。

我試着做以下幾點:

List a = new GremlinPipeline(graphDb.getVertices()).groupBy(new PipeFunction<Vertex, String>() { 
                  public String compute(Vertex vertex) { 
                    return "age"; 
                  }}, new PipeFunction<Vertex, Integer>() { 
                  public Integer compute(Vertex vertex) { 
                    return vertex.getProperty("age"); 
                  }}).toList(); 
System.out.println(a.toString()); 

但它返回我所有的頂點來代替。

如何對它們進行分組並根據屬性「年齡」計算組內的物品數量?

+0

嗨,你還可以接受Gremlin查詢來解決你的問題嗎? – LucaS

回答

0

試試這個:

這是我的代碼:

enter image description here

,這是輸出:

enter image description here

希望它可以幫助