How to send back the id of an element as a string

330 views
Skip to first unread message

Al Byers

unread,
Aug 27, 2018, 5:22:41 PM8/27/18
to Gremlin-users
I am looking for a work around for the problem that I have outstanding in which the following query:

Edge e = g.V(fromId).as('a').V(toId).addE(label).from('a').next()

returns and unregistered class ID error for ReferenceEdge

I have tried:

Object map = g.V(fromId).as('a').V(toId).addE(label).from('a').id().next()

but it also returns an error:

This works:

Object map = g.V(fromId).as('a').V(toId).addE(label).from('a').property('edgeId', __.id()).valueMap().next()

but I am thinking that there should be some way using Gremlin to return just the id as a string.



Stephen Mallette

unread,
Aug 28, 2018, 10:36:33 AM8/28/18
to Gremlin-users
That last one works but you aren't sending back the id in that case, right? There still must be some serialization configuration you're missing, but I'm not sure what it it is. That's more of a question for JanusGraph folks, but I think you have a separate thread about that.


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/24d51df4-f9d0-4bf4-aad0-7f5ae73d5dab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Al Byers

unread,
Aug 28, 2018, 7:16:12 PM8/28/18
to Gremlin-users
Yes, so I thought about how to send back the edgeId and came up with:
Object id = g.V(fromId).as('a').V(toId).addE(label).from('a').property('edgeId', __.id()).properties('edgeId').value().next()

But it returns a Long (eg. 176328) and I didn't expect that for an edge id.  Is "__" in "__.id()" not pointing to the newly created edge?

But I found something that works better:
String eStr = "g.V('${fromId}').as('a').V('${toId}').addE('${label}').from('a').next().id().toString()"
org.apache.tinkerpop.gremlin.driver.ResultSet result = client.submit(eStr)
CompletableFuture <Edge> cf = result.all()
Object eId = cf.get()[0].getString()


This returns what I thought an edge id should look like: "1g5v-2gm0-e8l-3s20". Looks messy, though. Seems like there should be a simpler way.

Anyway, thanks for your help.

Regards,
Al

Jason Plurad

unread,
Aug 28, 2018, 7:52:19 PM8/28/18
to Gremlin-users
Based on the example code project from the other thread, this works

// Java driver
String gremlin = "g.addV('a').as('a').addV('b').addE('to').from('a').id().next()";
ResultSet results = client.submit(gremlin);
RelationIdentifier edgeId = results.one().get(RelationIdentifier.class);
LOGGER
.info(edgeId.toString());

// Java GLV
RelationIdentifier relId = (RelationIdentifier) g.E().id().next();
LOGGER
.info(relId.toString());

The edge id in JanusGraph is a RelationIdentifier object even though it can be seen represented as a String.

Al Byers

unread,
Aug 28, 2018, 8:31:44 PM8/28/18
to Gremlin-users
Jason,

Yes, I saw the other thread. 
Thanks again. This level of support blows my mind. You are very kind and generous.
And that goes for Stephen and Robert. The support that I have received in the past 24 hours has been incredible.

Regards,
Al
Reply all
Reply to author
Forward
0 new messages