Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number of nodes/edges in a large graph via Gremlin?

Tags:

gremlin

What is the easiest & most efficient way to count the number of nodes/edges in a large graph via Gremlin? The best I have found is using the V iterator:

gremlin> g.V.gather{it.size()}

However, this is not a viable option for large graphs, per the documentation for V:

The vertex iterator for the graph. Utilize this to iterate through all the vertices in the graph. Use with care on large graphs unless used in combination with a key index lookup.

like image 786
bcm360 Avatar asked Jun 20 '13 13:06

bcm360


1 Answers

I tried the above, it didn't work for me. For some of you, this may work:

gremlin> g.V.count()
{"detailedMessage":"Query parsing failed at line 1, character position at 3, error message : no viable alternative at input 'g.V.'","code":"MalformedQueryException","requestId":"99f749db-c240-9834-aa12-e17bb21e598e"}
Type ':help' or ':h' for help.
Display stack trace? [yN]
gremlin> g.V().count()
==>37
gremlin> g.E().count()
==>45
gremlin> 

Use g.V().count instead of g.V.count(). (For those where the other command errors out).

like image 101
kishore Avatar answered Oct 21 '22 09:10

kishore