Adding vertices with custom ids

1,202 views
Skip to first unread message

David Heryanto

unread,
Feb 11, 2016, 1:43:06 PM2/11/16
to Aurelius
Hi

I'm trying to insert vertices into Titan with custom id but currently having some problem. According to http://s3.thinkaurelius.com/docs/titan/1.0.0/titan-config-ref.html I can set 
graph.set-vertex-id=true
to enable the use of custom id.

Here is my code:

TitanFactory.Builder config = TitanFactory.build();
config
.set("storage.backend", "berkeleyje");
config
.set("storage.directory", "C:/data/titan");
config
.set("graph.set-vertex-id", true);

Graph graph = config.open();
graph
.addVertex(T.id, 1);


I received this exception:
java.lang.UnsupportedOperationException: Vertex does not support user supplied identifiers
at org.apache.tinkerpop.gremlin.structure.Vertex$Exceptions.userSuppliedIdsNotSupported(Vertex.java:163)
at com.thinkaurelius.titan.graphdb.tinkerpop.TitanBlueprintsTransaction.addVertex(TitanBlueprintsTransaction.java:89)
at com.thinkaurelius.titan.graphdb.tinkerpop.TitanBlueprintsGraph.addVertex(TitanBlueprintsGraph.java:115)
at Main.main(Main.java:37)

Any idea about this?
Thanks

David

unread,
Feb 15, 2016, 11:54:09 AM2/15/16
to Aurelius
If you look at this change:

https://github.com/thinkaurelius/titan/commit/0af6c47e24f11f18fb4b559c58e30e1a8a3e54d1

(3rd change listed)

the following line was added to TitanBlueprintsTransaction.java:

if (ElementHelper.getIdValue(keyValues).isPresent()) throw Vertex.Exceptions.userSuppliedIdsNotSupported();

The TinkerPop 3.x ElementHelper code does this:

    public static Optional<Object> getIdValue(final Object... keyValues) {
        for (int i = 0; i < keyValues.length; i = i + 2) {
            if (keyValues[i].equals(T.id))
                return Optional.of(keyValues[i + 1]);
        }
        return Optional.empty();
    }

The way I read that...getIdValue() will return something in Optional in your scenario - the 1 ID value you specified.

The isPresent() check back in TitanBlueprintsTransaction will return "true" and will throw  userSuppliedIdsNotSupported

Despite what the Titan documentation may say, this "feature" is disabled in Titan.

There were plenty of cautions about using this capability previously on Stack overflow and the mailing list:
http://stackoverflow.com/questions/17397466/how-to-overwrite-vertices-id-in-titan-database

I will open an Issue to remove the capability from the documentation given the way
the code reads today...although without Matthias commenting, we can't be 100% sure if
he intended to permanently remove this capability or if he was on his way to something else
and never got to it.

I noticed that if the code is altered around the isPresent() check to allow setting of a custom ID,
there appears to be no logic later to appropriately set an ID and another exception is encountered.

David Heryanto

unread,
Feb 29, 2016, 4:56:41 AM2/29/16
to Aurelius
Thanks for the response. Actually I tried modifying the source code as well to force the insertion of custom id but I receive another error. It seems that it does not support custom id as of version 1.0.0.

Reply all
Reply to author
Forward
0 new messages