What is the ordering of group?
For instance (on Tinkerpop modern)
g.V().group().by('age').by('name')
gives
[{32=[josh], 35=[peter], 27=[vadas], 29=[marko]}]
There must be some logic to it?
(Understanding this would help me for unit testing, allowing me to compare results that are actually the same)
g.V().group().by('age').by('name')
gives
[{32=[josh], 35=[peter], 27=[vadas], 29=[marko]}]
There must be some logic to it?
(Understanding this would help me for unit testing, allowing me to compare results that are actually the same)
Solution
Gremlin doesn't offer too many order guarantees. I think
group() by default uses a regular old HashMap for it's data structure. If you want an order you would want to specifically specify an order() - for example:
I suppose you could also force use of aLinkedHashMap:
The first being an insertion order given however the underlying graph iterates vertices fromV()or with an explicitorder()as in the second. I'd say it's possible better to do the explicit order against vertices rather than than my first example where it does a in-memory sort of theMapas it's possible you might get some performance improvement there depending on your graph. Hard to say which is nicer as thewithSideEffect()approach isn't quite as readable. (Note that in my Groovy examples above, the[:]will resolve to aLinkedHashMapby default.)