Reputation: 12191
When I store a vertex in TinkerGrapg I see that the ids are long:
{TinkerVertex@7955} "v[304]"
when I do:
graph.V(304).next();
it doesn't work!
when I do:
graph.V("304").next();
it doesn't work!
when I do:
graph.V(304l).next();
or
graph.V(new Long(304)).next();
it works!
I am trying to use the same Gremlin code both against TinkerGraph and DSE Graph..The problem is that one returns long
and the other one as strings
I am curious how I could make the same Gremlin work with int/long and String ids at the same time.. is this a problem of the API?
Thanks!
Upvotes: 0
Views: 204
Reputation: 46226
TinkerGraph uses and IdManager
which can coerce identifiers to different types. You can read more about that here but basically if you want to have g.V(1)
and g.V(1L)
both return a value you'd want to configure your TinkerGraph as follows:
gremlin> conf = new BaseConfiguration()
==>org.apache.commons.configuration.BaseConfiguration@552518c3
gremlin> conf.setProperty('gremlin.tinkergraph.vertexIdManager',"LONG")
gremlin> graph = TinkerGraph.open(conf)
==>tinkergraph[vertices:0 edges:0]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.addV(id, 1L)
==>v[1]
gremlin> g.addV(id, 2)
==>v[2]
gremlin> g.V(1)
==>v[1]
gremlin> g.V(1L)
==>v[1]
gremlin> g.V(2L)
==>v[2]
gremlin> g.V(2)
==>v[2]
In fact, even this works when you use an IdManager
:
gremlin> g.V("2")
==>v[2]
You can specify your own IdManager
implementation to TinkerGraph if you like - just supply the fully qualified classname to the configuration (i.e. instead of "LONG").
Upvotes: 4