Raghav Jajodia
Raghav Jajodia

Reputation: 469

Gremlin Python: Count vertices and its children in one query

I am trying to get the count of all vertices with a particular label and all its children in one query like so:

g.V().hasLabel('folder').has('folder_name', 'root').as_('a', 'b').select('a', 'b').by(__.count()).by(__.in_('items_belongs_to_folder').count()).toList()

This should ideally return [{a: 200, b: 400}], but I am instead getting a list like so:

[{a: 1, b: 0},{a: 1, b: 0},{a: 1, b: 0},{a: 1, b: 0},{a: 1, b: 0},{a: 1, b: 0},{a: 1, b: 0},....{a: 1, b: 0}]

How exactly can I achieve the desired result?

gremlinpython: 3.4.4 (latest)

Python 3.7

graph database: AWS Neptune

Upvotes: 4

Views: 802

Answers (1)

noam621
noam621

Reputation: 2856

You can try:

g.V().hasLabel('folder').has('folder_name', 'root').fold()
.project('a', 'b')
.by(count(local))
.by(unfold().in_('items_belongs_to_folder').count())

Upvotes: 0

Related Questions