Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Certain commands return nothing #49

Closed
juhasev opened this issue Apr 26, 2018 · 7 comments
Closed

Certain commands return nothing #49

juhasev opened this issue Apr 26, 2018 · 7 comments

Comments

@juhasev
Copy link

juhasev commented Apr 26, 2018

I am running into an issue with

g.V().drop()

which would drop all vertices. None of the drop queries work for some reason... Once you add iterate() this is supposed to work.

g.V().drop().iterate()

These work fine in Gremlin console but not via PHP.

Running JanusGraph 0.2.0 (w/ Cassandra & ElasticSearch) with bundled gremlin server.

From GremlinServer logs:

87565089 [gremlin-server-worker-1] INFO  org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor  - Initialized gremlin-groovy ScriptEngine with scripts/empty-sample.groovy
87565112 [gremlin-server-session-1] WARN  org.janusgraph.graphdb.transaction.StandardJanusGraphTx  - Query requires iterating over all vertices [()]. For better performance, use indexes
87565146 [gremlin-server-worker-1] INFO  org.apache.tinkerpop.gremlin.server.op.session.Session  - Session 22a0f71e-433f-4441-b804-5392101c7f74 closed
@dmill-bz
Copy link
Owner

dmill-bz commented Apr 26, 2018

Hey!

Are you saying that both g.V().drop() and g.V().drop().iterate() are failing in php?
Can you let me know what version of the gremlin-php driver you are using as well? And how you're sending the request (using Connection::send() or Connection::run()?)

Bellow is some info I gathered up concerning the setup. Let me know if there's anything out of place:

(Edit: A failing sample php code would be great. Looks like you're using sessions so that might be something to look into)

@juhasev
Copy link
Author

juhasev commented Apr 26, 2018

Didn't know about the run method! It works with it just fine. We should add that to the documentation and also mention requirement for using next() to get v extracted from a method. Like:

snowboarding = g.addV("hobby").property("name","Snow Boarding").next()

fails without the next(). All examples are written for gremlin console and there seems to be a lot of differences how things need to be approached. This is my first real journey to Gremlin.

@dmill-bz
Copy link
Owner

dmill-bz commented Apr 26, 2018

Yeah seems like there are a few things worth noting. Some of which I should definitely add to the documentation.

NO CONTENT 204 return error

The server processed the request but there is no result to return (e.g. an Iterator with no elements) - there are no messages remaining in this stream.

There is such a thing as an "No content return error". This is how it's communicated back from the server and hasn't been changed on the TinkerPop end because it is (or has been) very useful for debugging purposes. This error just means the server isn't returning any info. It's not really an error so to speak.

Because the driver bubbles up server issues, any empty return value will throw a similar error on the php end (ServerException code 204). It is worth noting that even though you get this error your code is still being executed.
The reason why you get no error on Connection::run() is because run ignores any info returned from the server by default. Just sends and forgets.

People implementing the driver should consider doing one of two things :

$db = new Connection([
     // ... config here ...
]);
$db->open();
try {
   $db->send("g.V().drop()");
} catch (Exception $e) {
   if($e instanceof ServerException && $e->getCode() == 204) {
      /** 
       * best practice would be to log a warning in your application as it will help with 
       * debugging if you have an issue with your gremlin query.
      */
      return []; // return an empty set.
   } else {
      throw $e;
   }
}

The other option is (gremlin-php v 2.2.0+):

$db = new Connection([
     "emptySet" => true, // this will automatically send you an empty array in place of an error.
     // ... config here ...
]);

Worth noting the second case does no log a warning. So some gremlin error debugging may be obscured by this.
In the first case it is obviously best to wrap the the driver's send() in your own send method with the try{}catch{} logic.

Iterations

The way the console works is that it automatically iterates your queries. It's a comfort feature.
Unfortunately whether it be gremlin sent through drivers or in native java you need to do those iterations manually.
It's very misleading because most/all the documentation is done using gremlin console.
The most common (but not the only) cases are like you mentioned:

g.V().drop().iterate();
g.addV("hobby").property("name","Snow Boarding").next();

@dmill-bz
Copy link
Owner

Let me know if you think of a good way of structuring the documentation to mention these points.
Also just to reiterate, you should be using Connection::send() in your case if you care at all about potential server side errors (like server side transaction conflicts)

@juhasev
Copy link
Author

juhasev commented Apr 26, 2018

Great comments. I totally agree. This has been rather confusing experience due to lack of documentation / relatively small community. Even Tinkerpop 3 docs are outdated right at the tutorial. Need to find some good cook book / reference on this.

@dmill-bz
Copy link
Owner

I just skimmed it but this looked like a good guide : http://kelvinlawrence.net/book/Gremlin-Graph-Guide.html It won't make any mentions of iterations but you can pretty much ask here or on the gremlin user list if you have any questions regarding that.
Otherwise going to the "1. Reference Documentation > The Traversal section" for the correct TinkerPop version is often good too. Look here (Janus graph 0.2.0 uses TinkerPop 3.2.8)

If you have any questions on the driver or gremlin in general feel free to create a new issue. I'll keep this open as a reminder to edit the documentation a bit. Maybe a quick start guide might be useful.

@juhasev
Copy link
Author

juhasev commented Apr 27, 2018

I discovered his book yesterday and it is indeed best Gremlin guide out there. Thanks for all the detailed the help and pointers!

@dmill-bz dmill-bz closed this as completed Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants