gremlintinkerpoptinkerpop-blueprinttinkergraph

Difference between traversal using gremlin and methods from Graph


Suppose I've the following simple graph.

enter image description here

I see two ways of traversing this graph

Option 1

I can use the following API provided by the Graph class

Graph factory = ...
factory.getVertices("type", "Response");

Option 2

I can also use GremlinPipeline API as documented here

Graph g = ... // a reference to a Blueprints graph
GremlinPipeline pipe = new GremlinPipeline();
pipe.start(g.getVertex(1))

My question are


Solution

  • There are two APIs for getting data because one represents a Blueprints-level which is a lower level of abstraction having utility-level functions for accessing graphs and Gremlin-level which is a higher level of abstraction having a much higher degree of expressivity when traversing graphs. The design principle is built around the fact that Blueprints is an abstraction layer over different graph databases (i.e. Neo4j, OrientDB, etc) and that it needs to be simple enough for the implementations to be developed quickly. Gremlin however is a graph traversal language which works over the Blueprints API making it possible for Gremlin to operate over multiple graph databases.

    Your examples don't allow Gremlin to shine at all. Sure, in those cases, there really isn't a reason to choose one over the other. Here's a similar example which I think is better:

    // blueprints
    g.getVertices()
    
    // gremlin
    g.V
    

    Other than saving a few characters, Gremlin really isn't getting me anything. However, consider this Gremlin:

    g.V.out('knows').outE('bought').has('weight',T.gt,100).inV.groupCount().cap()
    

    I won't supply the Blueprints equivalent of that because it's a lot of code to type. You'll have to trust that this single line of Gremlin is worth many lines of code with tons of ugly looping.

    Most of the time, usage of the raw Blueprints API isn't really necessary for traversals. You'll find yourself using it for loading data, but other than that, use Gremlin.