Cannot Access Vertices with g.V(*vertexID*).next() in Java App

40 views
Skip to first unread message

Hayden Freedman

unread,
Mar 23, 2017, 4:25:19 PM3/23/17
to Gremlin-users
This is an extension of a problem that I was having in the Console. I am now trying to write a Java App incorporating Gremlin graph traversals. I have added the Blazegraph-Gremlin library to my app and I am working with data from a Blazegraph database. 
Here, I've written out a small demo to show my problem. Sorry for the excess of print statements, but I wanted to demonstrate in the output exactly what was happening at each step.

System.out.println("Show me first vertex you find");
System.out.println(g.V().next());
Vertex v1 = g.V().next();
System.out.println("Prove that the variable is set properly (it is)");
System.out.println(v1);
Object v1id = g.V().id().next();
System.out.println("Get the ID of the object to pass to g.V()");
System.out.println(v1id);
GraphTraversal<Vertex, Vertex> v2 = g.V(v1id);
System.out.println("Try to find the vertex given the ID");
Vertex v3 = g.V(v1id).next();
System.out.println(v3);

Output of the above code:

Show me first vertex you find
v[8080/source/sampledata1/008a46ce-d7f9-4c60-b7ca-1ccaa6ce7bbd/identifier]
Prove that the variable is set properly (it is)
v[8080/source/sampledata1/008a46ce-d7f9-4c60-b7ca-1ccaa6ce7bbd/identifier]
Get the ID of the object to pass to g.V()
8080/source/sampledata1/008a46ce-d7f9-4c60-b7ca-1ccaa6ce7bbd/identifier
ERROR 2017-03-23 16:20:44,463 1530 com.bigdata.Banner [main] Uncaught exception in thread
org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException

From the responses I received to previous posts, I was given the impression that this may be a bug in Blazegraph. With that said, I would appreciate any help/support I can get on the Gremlin side of things, since I am fairly committed to using Blazegraph at this point. If anyone has any syntax suggestions/sees something I am doing improperly/wants more details, please respond. I will be happy to provide more examples if necessary.

Thanks!


Stephen Mallette

unread,
Mar 23, 2017, 6:13:45 PM3/23/17
to Gremlin-users
I don't see anything really wrong with what your Gremlin code looks like. I mean - it looks like just some basic code to try things out and not really any complex logic that could be optimized further. I will note a few things:

With this:

Object v1id = g.V().id().next();

it seems that BlazeGraph was nice enough to return the same Vertex id as your prior command. TinkerPop does not enforce a deterministic order for element iteration. So don't rely on that unless you're sure about what BlazeGraph is doing. 

I also thing this part is weird give that you aren't running this in the Gremlin Console (which iterates results for you):

> System.out.println(v1id);
> GraphTraversal<Vertex, Vertex> v2 = g.V(v1id);
> System.out.println("Try to find the vertex given the ID");

I don't get why your output doesn't include that last println there. You get a FastNoSuchElementException which should only occur on iteration of the GraphTraversal which you didn't do. You merely initialized it. I don't know how that can happen. Are you sure you got the output right?  Given the problems you've had with id looks ups from BlazeGraph, I think the FastNoSuchElement is expected (unless they've patched something for you), but you should get it on this call:

> Vertex v3 = g.V(v1id).next();

when you next() the Traversal. I sorta wonder why you have this line at all:

> GraphTraversal<Vertex, Vertex> v2 = g.V(v1id);

It's not really doing anything at all in your sample code.





--
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-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/a7194b1c-65af-4f76-aae5-514a6534a2be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hayden Freedman

unread,
Mar 24, 2017, 9:32:13 AM3/24/17
to gremli...@googlegroups.com
Hi Stephen, thanks again for responding.

So it was my mistake to include the line GraphTraversal<Vertex, Vertex> v2 = g.V(v1id); You are correct that this line does not do anything. I had included it for a previous test and overlooked taking it out for my post on this page. So the code for the test should read: 

System.out.println("Show me first vertex you find");
System.out.println(g.V().next());
Vertex v1 = g.V().next();
System.out.println("Prove that the variable is set properly (it is)");
System.out.println(v1);
Object v1id = g.V().id().next();
System.out.println("Get the ID of the object to pass to g.V()");
System.out.println(v1id);
System.out.println("Try to find the vertex given the ID");
Vertex v3 = g.V(v1id).next();
System.out.println(v3);

Since I wasn't doing anything with that variable as you noted, the output will be the same.

It's really frustrating and perplexing for me that I am not able to complete these basic tasks. Being able to retrieve a specific vertex when given its vertex ID is a really critical functionality for the app I am writing. I feel like there must be a good way to do this and that I am just missing something obvious. 

--
You received this message because you are subscribed to a topic in the Google Groups "Gremlin-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gremlin-users/doUJl5XNBac/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/CAA-H438xDQrCsFf_54AS2qJC6i3j7MjjMf_2jHnzqoqxkQu%2B7w%40mail.gmail.com.
Message has been deleted

Stephen Mallette

unread,
Mar 24, 2017, 9:35:04 AM3/24/17
to Gremlin-users
Being able to retrieve a specific vertex when given its vertex ID is a really critical functionality for the app I am writing

That's critical to every graph application. I don't think the problem can be solved here on this list though. This doesn't appear to be a problem with Gremlin. It is an issue with the BlazeGraph implementation somehow. I think you will have to get some support directly from them.

Hayden Freedman

unread,
Mar 24, 2017, 9:44:44 AM3/24/17
to Gremlin-users
OK, understood. I'll try to seek out some help from the Blazegraph side of things.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Gremlin-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gremlin-users/doUJl5XNBac/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gremlin-user...@googlegroups.com.

--
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.

Stephen Mallette

unread,
Mar 24, 2017, 9:47:45 AM3/24/17
to Gremlin-users
Basically, every working TinkerPop Graph implementation should be able to do this:

gremlin> graph = TinkerGraph.open()
==>tinkergraph[vertices:0 edges:0]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> v = g.addV().next()
==>v[0]
gremlin> g.V(v)
==>v[0]
gremlin> g.V(v.id())
==>v[0]


To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/a5fcfb79-d433-4357-b8b7-cc41876ced42%40googlegroups.com.

Hayden Freedman

unread,
Mar 24, 2017, 10:01:52 AM3/24/17
to gremli...@googlegroups.com
This is really good to know, thank you.

To unsubscribe from this group and all its topics, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/CAA-H438GynqiEJxqkT%2BF%2BLrmMbdeNtp_AHs4-65%2BrSgWY4ORHA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages