gremlin-rs icon indicating copy to clipboard operation
gremlin-rs copied to clipboard

Question: using custom ids

Open skc11 opened this issue 10 months ago • 4 comments

Hi, is there a way to set our own Id property for vertices and edges when creating them ?

skc11 avatar Apr 13 '24 15:04 skc11

I need the same feature. Tryied passing ~id property and upsert with coalesce (could not implement because I can't underst how to use coalesce), but look like it is not possible to use a custom id.

andreclaudino avatar Jun 07 '24 00:06 andreclaudino

I do not believe TinkerPop3 has this ability out of the box. You can reference each Step here.

I did find that JanusGraph has the ability to store custom vertex IDs, here's the relevant documentation.

Ech0riginal avatar Jun 12 '24 16:06 Ech0riginal

I've had success doing it to JanusGraph via an anonymous traversal like inside a coalesce

g.V("custom_vertex_id").fold().coalesce::<Vertex, _>([__.unfold(), __.add_v("some_label_here") .property(gremlin_client::structure::T::Id, custom_vertex_id)])

But it doesn't seem like you can do on a traversal directly. If you try to do something like: graph.get_traversal().add_v("some_label_here").property(gremlin_client::structure::T::Id, custom_vertex_id) you fight the type system.

@wolf4ood The property() method there has a hard type requirement that key be &str, whereas the property() for an anonymous traversal (__ returns a TraversalBuilder) takes a key of type Into<GValue>. Not sure if that's intentional?

criminosis avatar Jul 02 '24 19:07 criminosis

I took a stab at adding custom id support in my fork's branch. They're featured in this PR if anyone wants to try the branch until it gets merged & release.

criminosis avatar Jul 13 '24 21:07 criminosis