0

我正在使用 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());

但它反而返回了我所有的顶点。

如何根据属性“年龄”对它们进行分组并计算组内的项目数?

4

1 回答 1

0

试试这个:

这是我的代码:

在此处输入图像描述

这是输出:

在此处输入图像描述

希望能帮助到你

于 2016-04-04T22:17:48.687 回答