Anthony
Anthony

Reputation: 917

With Gremlin, when using a groupCount() with more than one property, how can I order the results?

g.V().as('a').
 outE().as('r').
 inV().as('b').
 select('a', 'r', 'b').
 project('source','label','target').
 by(select('a').label()).
 by(select('r').label()).
 by(select('b').label()).
 groupCount().
 order(local).by(values, desc).
 unfold()

This query should work on any gremlin dataset.

sample output:

==>{source=Node, label=POINTS_AT, target=Node}=63
==>{source=Node, label=IS_RELATED_TO, target=Other}=14
==>{source=Other, label=POINTS_AT, target=Other}=3

I am just starting to learn Gremlin. This query does a groupCount on the out vertex label, edge label, and in vertex label and orders the results by the values, which are just the counts.

The keys are Map entries with multiple values 'source', 'label', and 'target'. I would like to order the results by the edge label, then by the source label, and by the target label last. How can I accomplish this?

Also, is there is a better way to approach this than the query I came up with?

Upvotes: 2

Views: 579

Answers (1)

Kelvin Lawrence
Kelvin Lawrence

Reputation: 14371

Without your data set I am not sure if this is exactly what you want but does this do what you need?

g.V().as('a').
 outE().as('r').
 inV().as('b').
 project('source','label','target').
 by(select('a').label()).
 by(select('r').label()).
 by(select('b').label()).
 groupCount().
 order(local).
   by(select(keys).select('source')).
   by(select(keys).select('target')).
   by(select(keys).select('label')).
 unfold()

You can add desc to any of the by modulators if that is what you need.

Upvotes: 3

Related Questions