janusgraph icon indicating copy to clipboard operation
janusgraph copied to clipboard

adding vertex with custom id?

Open chrislusf opened this issue 9 years ago • 2 comments

When g.addV(), there are no way to specify the id. The id is auto-generated.

Is it possible to specify the id directly? We have UUID for all entities. Avoiding another redirection will save the extra index on UUID.

chrislusf avatar Jan 18 '17 01:01 chrislusf

Once the database is initialized using this "graph.set-vertex-id=false", which is the default, you can't set the IDs. What it means is that, exporting/importing data using GraphReader's on an existing graph would just duplicate the whole thing up. In my case, I have a dev graph with many vertices that I'd like to export to some other graph and use the same ID as in the previous graph so it is sort of like "static" ID. If I could set the ID or create using that ID would be awesome.

What I had to do was to create a "shadow" ID property to store that ID, so I'd traverse that shadow first, if exists I use that, otherwise just use the vertex.id() value.

I had to create my own GraphReader to traverse first, update if found, if not create and set the shadow so I could use it...

Now I have an overhead to traverse instead of just going straight to the ID itself using indexes.

rafatuita avatar Jan 18 '17 16:01 rafatuita

#148 has been merged which restores support for custom Long vertex ids in JanusGraph. Note that only Long ids are supported and they must be converted to valid JanusGraph ids for use in g.addVertex(T.id, id). See recently updated method documentation.

sjudeng avatar Jun 17 '17 12:06 sjudeng