Reputation: 751
Cosmos DB doesn't support grouping by anything that is not a primitive (I've already sent a request for them to fix this). But in the meantime, how could I go by doing groupCount() by multiple values without needing arrays, or using lambdas (which are also not supported)
This is what I would like to do
g.V().groupCount().by(values('id', 'name').fold())
But I cannot use values().fold(). Any suggestions?
Upvotes: 1
Views: 509
Reputation: 10904
Hmm, the only (ugly) workaround I can think of is this:
g.V().
group().
by('id').
by(groupCount().by('name')).
unfold().
match(__.as('kv').select(keys).as('k'),
__.as('kv').select(values).unfold().as('v')).
project('key','value').
by(union(select('k'), select('v').by(keys)).fold()).
by(select('v').by(values))
So basically a nested grouping by primitive values, followed by an unfolding and regrouping into a map made of only primitive keys. The result will look similar to this:
==>[key:[id1,name1],value:1]
==>[key:[id2,name2],value:2]
==>[key:[id3,name3],value:1]
...
UPDATE
Since CosmosDB doesn't support match()
, the query would look like this:
g.V().
group().
by('id').
by(groupCount().by('name')).
unfold().as('kv').
select(keys).as('k').
select('kv').select(values).unfold().as('v').
project('key','value').
by(union(select('k'), select('v').by(keys)).fold()).
by(select('v').by(values))
Upvotes: 2