Reputation: 930
In this test we can see that it does not allow to insert the same vertex ID for the same datatype, but for different datatype it allows it.
gremlin> graph = TinkerGraph.open()
==>tinkergraph[vertices:0 edges:0]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.V()
# generate vertex id automatically by UUID.randomUUID()
gremlin> g.addV().property(id,UUID.randomUUID())
==>v[b47bb233-9a2a-49c8-8ada-0ac0fe9be6f2]
gremlin> g.V()
==>v[b47bb233-9a2a-49c8-8ada-0ac0fe9be6f2]
# generate vertex id manually as UUID datatype.
gremlin> g.addV().property(id,UUID.fromString("c2d673de-2425-4b42-bc1e-68ff20e3b0a8"))
==>v[c2d673de-2425-4b42-bc1e-68ff20e3b0a8]
gremlin> g.V()
==>v[c2d673de-2425-4b42-bc1e-68ff20e3b0a8]
==>v[b47bb233-9a2a-49c8-8ada-0ac0fe9be6f2]
# generate vertex id manually as STRING datatype.
gremlin> g.addV().property(id,"c2d673de-2425-4b42-bc1e-68ff20e3b0a8")
==>v[c2d673de-2425-4b42-bc1e-68ff20e3b0a8]
gremlin> g.V()
==>v[c2d673de-2425-4b42-bc1e-68ff20e3b0a8]
==>v[b47bb233-9a2a-49c8-8ada-0ac0fe9be6f2]
==>v[c2d673de-2425-4b42-bc1e-68ff20e3b0a8]
# here we can see the vertex with same id duplicated.
gremlin> g.V().id()
==>c2d673de-2425-4b42-bc1e-68ff20e3b0a8
==>b47bb233-9a2a-49c8-8ada-0ac0fe9be6f2
==>c2d673de-2425-4b42-bc1e-68ff20e3b0a8
# trying to insert it again as UUID datatype.
gremlin> g.addV().property(id,UUID.fromString("c2d673de-2425-4b42-bc1e-68ff20e3b0a8"))
Vertex with id already exists: c2d673de-2425-4b42-bc1e-68ff20e3b0a8
# trying to insert it again as STRING datatype.
gremlin> g.addV().property(id,"c2d673de-2425-4b42-bc1e-68ff20e3b0a8")
Vertex with id already exists: c2d673de-2425-4b42-bc1e-68ff20e3b0a8
Upvotes: 1
Views: 143
Reputation: 1581
It is expected behavior. You can do:
gremlin> g.V().project('id', 'class')
.by(id())
.by(map{it->it.get().id().getClass()})
==>[id:b6609a02-4574-4e6f-87ab-6ea3edaa9e55,class:class java.lang.String]
==>[id:b6609a02-4574-4e6f-87ab-6ea3edaa9e55,class:class java.util.UUID]
Apparently, comparing the String object and the UUID object always results in false.
By the way, the graph you opened is a TinkerGraph which is shipped with JanusGraph as part of Apache TinkerPop. JanusGraph itself does not allow vertex id's to be specified, unless explicitly configured that way.
Upvotes: 2