Gremlin user defined steps using the Titan query API

53 views
Skip to first unread message

Jean-Baptiste Musso

unread,
Mar 3, 2015, 1:37:05 PM3/3/15
to aureliu...@googlegroups.com
Hi there,

Using Titan v0.5.4. Is there a way to hit the Titan API from within a Gremlin user defined step?

I'm trying to define a .followers() step which takes an optional count parameter. I thought I could be doing something that'd resemble this:

Gremlin.defineStep('followers', [Vertex, Pipe], { count = 20 ->
  query().labels("follows").direction(IN).orderBy("timestamp", Order.DESC).limit(count).vertices()._()
})

This obviously doesn't work and Rexster returns the following error:

error: "javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.query() is applicable for argument types: () values: [] Possible solutions: every(), every(groovy.lang.Closure), grep(), grep(java.lang.Object), dump(), any()"


Until TP3 is out, the goal is to allow a query such as g.query().has('label', 'user').has('name', 'foobar').vertices()._().followers(50) and efficiently retrieve foobar's latest 50 followers.

I'm not even sure this is feasible. Any ideas?

Thanks,

Jean-Baptiste

Stephen Mallette

unread,
Mar 4, 2015, 6:51:31 AM3/4/15
to aureliu...@googlegroups.com
I don't think you can start with query()....Would this work:

Gremlin.defineStep('followers', [Vertex, Pipe], { count = 20 ->
  _().transform{it.query().labels("follows").direction(IN).orderBy("timestamp", Order.DESC).limit(count).vertices()).scatter()
})

--
You received this message because you are subscribed to the Google Groups "Aurelius" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraph...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aureliusgraphs/49634d17-4880-4a31-8180-826969c734c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stephen Mallette

unread,
Mar 4, 2015, 6:52:10 AM3/4/15
to aureliu...@googlegroups.com
Oops - minor syntax error in the last post:

Gremlin.defineStep('followers', [Vertex, Pipe], { count = 20 ->
  _().transform{it.query().labels("follows").direction(IN).orderBy("timestamp", Order.DESC).limit(count).vertices()}.scatter()
})

Jean-Baptiste Musso

unread,
Mar 4, 2015, 7:27:04 AM3/4/15
to aureliu...@googlegroups.com
On Wed, Mar 4, 2015 at 12:52 PM, Stephen Mallette <spmal...@gmail.com> wrote:
Oops - minor syntax error in the last post:

Gremlin.defineStep('followers', [Vertex, Pipe], { count = 20 ->
  _().transform{it.query().labels("follows").direction(IN).orderBy("timestamp", Order.DESC).limit(count).vertices()}.scatter()
})


Indeed, you can't start with query(). The _().transform{/*...*/}.scatter() trick works like a charm!

Thanks Stephen,

Jean-Baptiste
Reply all
Reply to author
Forward
0 new messages