GitHub user mattallenuk opened a pull request:
https://github.com/apache/tinkerpop/pull/922
TINKERPOP-1959: Ability to send a script to the Gremlin Server.
Hiya,
Submitting a PR for consideration re sending a script to a Gremlin server.
I've added an eval() function to GraphTraversal and TraveralSource classes.
This function takes an optional script string and bindings map. If a script is
provided it will be sent directly to the server, discarding any previous glv
steps, if no script is provided one will be built from the previously set glv
steps.
RemoteStrategy class has been changed to handle submission of eval
operations to the DriverRemoteConnection.
Bytecode class has had a toScript() function added that takes the glv
instructions and produces a script with bindings.
Traversal class has been changed to handle responses from eval op execution.
I wanted to have the option to build from glv instructions as I'll be using
the library to access an Azure CosmoDB which currently doesn't support bytecode
but when it does it will make it much easier to update projects to using
bytecode by removing the eval function and replacing with one of the other
terminal actions.
I do have a couple of queries regarding the proposed changes:
1) Is it safe to assume that a returned value not containing a bulk
property was executed by an eval op?
When parsing the returned data from the server in the TraversalSource class
it appears that any data returned from a bytecode op contains a bulk property.
Can it be assumed then that any return value that doesn't contain a bulk
property is a valid return value for eval op, or should there be some sort of
checking in place?
```
_getNext() {
while (this.traversers && this._traversersIteratorIndex <
this.traversers.length) {
let traverser = this.traversers[this._traversersIteratorIndex];
if (traverser.bulk && traverser.bulk > 0) {
traverser.bulk--;
return { value: traverser.object, done: false };
} else if (traverser.bulk === undefined) {
return { value: traverser, done: true }
}
this._traversersIteratorIndex++;
}
```
2) Should every parameter be bound when building a dynamic script?
The Bytecode::toScript() function converts any glv parameters into bindings
to be sent to the server. Should this make consideration for parameters that
are likely not set by users. For example g.addV('flowers', 'Lilac'), can it be
assumed that flowers was set by the implementer and Lilac by a user? If so
should the function be changed to only bind parameters we can assume are set by
users?
3) Does the unit test need to be more thorough and check more varied
instructions and more complex glv queries/instructions?
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/mattallenuk/tinkerpop TINKERPOP-1959
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/tinkerpop/pull/922.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #922
----
commit b6478d666407656bc1cfc749a81d3e1ad6f06692
Author: Matthew Allen <matt.allen@...>
Date: 2018-08-23T14:48:36Z
Initial Commit for TINKERPOP-1959 solution.
commit c04ddae8a5793177d7515629358346d91be73e43
Author: Matthew Allen <matt.allen@...>
Date: 2018-08-24T15:14:29Z
Refactor of RemoteStrategy apply()
commit 090f1394a82be9bfd8fede85fa75655ab1f0f249
Author: Matthew Allen <matt.allen@...>
Date: 2018-08-24T23:02:27Z
Fix on eval() incorrect documentation
----
---