User Defined Steps for orientDB Handlers (Server Plugins)
OrientDB has Handlers (Server Plugins). Handlers allow writing custom functions. For example, there is a step
union
in Gremlin. In OrientDB, I can write my own function called customUnion
using the handlers.
Question: How can I call the custom function of OrientDB (or step of Gremlin) in the Gremlin console? Also, I am using the Gremlin Java API, so I need to call the custom function customUnion
in Gremlin Java API.
I have created the same question on OrientDB: https://github.com/orientechnologies/orientdb/issues/10003
It seems I need to configure the Gremlin server somehow to use my customUnion
function(step), and then I can write my custom traversals in Java to use it in the Java API. However, I cannot find any tutorial for this in TinkerPop3 or orientDBGitHub
Handlers (Server Plugins) and Gremlin · Issue #10003 · orientechnol...
Handler (Server Plugin) is the best solution for the feature, but it seems I cannot use my custom function (handler) in the Gremlin query. Is it really a limitation of Gremlin, or is there any way ...
2 Replies
If i understand correctly, you have OrientDB running in Gremlin Server and you connect with the
gremlin-driver
(which you referred to as the Java API). Under this model, there is no way to call functions outside of those of the Gremlin language. When you use the "Java API" in this remote fashion you are sending Gremlin bytecode to the server and it can only encode Gremlin steps to that bytecode. In recent times we've added a call()
step to Gremlin which would conceivably allow a graph like OrientDB to expose custom functions like those you are referring ot through it. So you could do something like g.V().call('customUnion')
but I imagine OrientDB hasn't made use of that yet. The only way you could access these sorts of provider specific features would be by sending scripts instead of bytecode to the server. With scripts which are basically just Groovy code, anything you could do in Java would be possible from a remote context.
As I write this I had an interesting thought actually. with lambdas enabled on the server you could probably do a poor-man's call()
wity bytecode by doing something like:
I'm not sure how "customUnion" works so i've made up the argument in the example above but perhaps that could be a workaround for you. that Lambda forces the bytecode traversal to be executed as Groovy so you still get the benefit of using the "Java API" from the client-side (but not the server-side).Thanks a lot @spmallette. I got it.
I will try 'g.V().call('customUnion')', but as you said, perhaps it is not supported in OrientDB yet.
Other solutions look like a hack and so i don't want to use it.
Do you mind if I post your answer on github in above issue? Or you can do it yourself. I just want to record you answer.