GroupBy using GremlinPipeline with OrientDB

时间:2016-04-04 17:28:00

标签: orientdb gremlin orientdb-2.1

I'm using the Java embedded version of OrientDB and I wanted to execute some gremlin queries. So I'm using GremlinPipeline to do this. I was wondering how to do a groupBy.

Say each vertice contains a property "age", I want to do a group by on this property.

I tried doing following :

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());

But it's returning me all the vertices instead.

How to group them and count the number of items inside a group according to the property "age" ?

1 个答案:

答案 0 :(得分:0)

试试这个:

这是我的代码:

enter image description here

,这是输出:

enter image description here

希望有所帮助