我正在使用 Java 嵌入式版本的 OrientDB,我想执行一些 gremlin 查询。所以我使用 GremlinPipeline 来做到这一点。我想知道如何做一个groupBy。
假设每个顶点都包含一个属性“年龄”,我想对该属性进行分组。
我尝试执行以下操作:
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());
但它反而返回了我所有的顶点。
如何根据属性“年龄”对它们进行分组并计算组内的项目数?