Using and() / or() in Gremlin 3

1,261 views
Skip to first unread message

Erik Wittern

unread,
May 14, 2015, 11:17:55 AM5/14/15
to gremli...@googlegroups.com
Hi,

we have been using Titan with TinkerPop 2.x for a while now and are switching to TinkerPop3 at the moment. I have some trouble translating existing queries, tough. The queries make frequent use of and() and or() statements, for example to find all users that are authors of a book or whose position and description match certain criteria. In Gremlin 2.x, I used the following query:

g.V('type','User').and(_().out('author').has('type','Book'),_().or(_().has('position',CONTAINS,'staff'),_().has('description',CONTAINS,'researcher'))).as('user').select

Now, in Gremlin 3, I try something similar:

g.V().has('type','User').and(out('author').has('type','Book'),or(has('position',CONTAINS,'staff'),has('description',CONTAINS,'researcher'))).as('user').select()


However, I get the following errors (even though I clearly pass a String to out()):

java.lang.RuntimeException: javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.out() is applicable for argument types: (java.lang.String) values: [feature]\nPossible solutions: get(java.lang.String), put(java.lang.String, java.lang.Object), wait(), any(), dump(), wait(long)\"}"

What am I doing wrong? I am also unclear about the documentation at http://tinkerpop.incubator.apache.org/docs/3.0.0.M8-incubating. For and(), examples show usage similar to my attempts: and(out(...),has(...)). However, for or(), the examples look like this: or(__.out(...),__.has(...)). What is the difference between these approaches?

Best regards,

Erik

Daniel Kuppitz

unread,
May 14, 2015, 11:55:26 AM5/14/15
to gremli...@googlegroups.com
Hi Erik,

in order to use .and(out()...) you have to

static import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.*

Without the static import you need to use the verbose format: .and(__.out()...).

Cheers,
Daniel


--
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/f04e3c57-63e9-48ef-b7a4-1f8079163080%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Erik Wittern

unread,
May 14, 2015, 12:35:45 PM5/14/15
to gremli...@googlegroups.com
Hi Daniel,

thanks for the reply! I tried your suggestion, using now (as a simple example):

g.V().or(__.has('type','User'),__.out('author'))

Still, I am getting errors:

"{\"message\": \"java.lang.RuntimeException: javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.tinkerpop.gremlin.process.graph.util.DefaultGraphTraversal.or() is applicable for argument types: (com.tinkerpop.gremlin.process.graph.util.DefaultGraphTraversal, com.tinkerpop.gremlin.process.graph.util.DefaultGraphTraversal) values: [[HasStep([type,eq,API])], [VertexStep(OUT,[invocation],vertex)]]\nPossible solutions: sort(), any(), min(), grep(), max(), sum()\"}"

Any other idea what I might be doing wrong?

Daniel Kuppitz

unread,
May 14, 2015, 2:26:18 PM5/14/15
to gremli...@googlegroups.com
I'm not able to reproduce this behavior. What's the context in which you're executing your queries? Does it work in the REPL? Does it work using curl? Both worked for me:

REPL:

gremlin> Gremlin.version()
==>3.0.0.M8
gremlin> g.V().or(__.has("name", "marko"), __.out("created")).values("name")
==>marko
==>josh
==>peter

curl:

daniel@cube /projects/apache/incubator-tinkerpop ((detached from 3.0.0.M8)) $ curl --silent --get 'http://localhost:8182' --data-urlencode 'gremlin=g.traversal().V().or(__.has("name", "marko"), __.out("created")).values("name")' | python -mjson.tool
{
    "requestId": "91e0576a-0911-47a4-af1d-ab0bb2d0393a",
    "result": {
        "data": [
            "marko",
            "josh",
            "peter"
        ],
        "meta": {}
    },
    "status": {
        "attributes": {},
        "code": 200,
        "message": ""
    }
}

Note that .traversal() has to be called explicitly in Gremlin Server 3.0.0.M8. However, it doesn't seem to be the problem in your case, since you're getting a totally different error.

Cheers,
Daniel


Erik Wittern

unread,
May 14, 2015, 3:48:01 PM5/14/15
to gremli...@googlegroups.com
Hi Daniel, 

I appreciate you taking the time to look into this - thank you very much!

I am using a slightly older version 3.0.0M7. I tried the REPL, here is the output:

gremlin> Gremlin.version()
==>3.0.0.M7

gremlin
> g.V().or(__.has("name", "marko"), __.out("created")).values("name")
No signature of method: com.tinkerpop.gremlin.process.graph.util.DefaultGraphTraversal.or() is applicable for argument types: (com.tinkerpop.gremlin.process.graph.util.DefaultGraphTraversal, com.tinkerpop.gremlin.process.graph.util.DefaultGraphTraversal) values: [[HasStep([name,eq,marko])], [VertexStep(OUT,[created],vertex)]]
Possible solutions: sort(), max(), sum(), any(), grep(), min()

Can it be the older version?

Cheers,

Erik

Erik Wittern

unread,
May 14, 2015, 3:51:03 PM5/14/15
to gremli...@googlegroups.com
Oh, I also tried with traversal:

gremlin> g.traversal().V().or(__.has("name", "marko"), __.out("created")).values("name")
No signature of method: com.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph.traversal() is applicable for argument types: () values: []


...but I assume that is not needed in M7?!

Erik Wittern

unread,
May 14, 2015, 5:44:29 PM5/14/15
to gremli...@googlegroups.com
I think I found the solution: in M8, the query works:

gremlin> Gremlin.version()
==>3.0.0.M8-incubating
gremlin
> g.traversal().V().or(__.has('name','marko'),__.out('created')).values()
==>marko

Time to upgrade...

Daniel, thanks again for the support.
Reply all
Reply to author
Forward
0 new messages