Reputation: 7210
Is it possible to create an edge between two vertices without the actual vertex object and just the IDs of the vertices in gremlin?
Normally you would do something like
e = g.addEdge(v1, v2, 'knows')
to create and edge where v1
, and v2
are vertex objects.
I would like to do something
e = g.addEdge(256, 512, 'knows')
where 256
and 512
are the IDs of the vertices.
Upvotes: 1
Views: 571
Reputation: 389
Surely you can just do this:
e = g.addEdge(g.v(256), g.v(512), 'knows')
This fails with an IllegalArgumentException if either vertex doesn't exist
Upvotes: 0
Reputation: 46216
That is not possible given the semantics of the Blueprints API (that Titan implements). If you really need that functionality, you could implement a GraphWrapper (like ReadOnlyGraph
or PartitionGraph
) and add that method. That might be a lot of boilerplate code to maintain for just one function though.
If you are using Gremlin Groovy, I think the better way would be to just do some meta programming with groovy to append in that method on the Graph
interface...something like:
Graph.metaClass.addEdge = { final Long outVertex, final Long inVertex, final String label ->
return ((Graph) delegate).addEdge(null, g.v(outVertex), g.v(inVertex), label);
}
You obviously might want some error handling around those vertex lookups, but that's the generally idea.
Upvotes: 3