Use local variables for remote console connection

84 views
Skip to first unread message

Florian Hockmann

unread,
Mar 21, 2017, 11:35:27 AM3/21/17
to Gremlin-users
Hi,

I am often working with a file that contains data which I want to use as a starting point for a traversal. So something like this:
userNames = new ArrayList<String>()
new File('myUsernames.txt').eachLine{ line -> userNames.add(line)}
g
.V().has('userName', within(userNames)).out('bought').values('productName').dedup()

This is of course just an example. The point is that I want to use the Gremlin Console to connect to a remote Gremlin Server and execute a traversal that uses data from my local machine (stored in the variable userNames in the example above).

I have no problem doing this when I use the Gremlin Console on the same machine Gremlin Server is running on, but I don't know how to send the data over a remote connection. Is there any way to do this?

Regards,
Florian

Stephen Mallette

unread,
Mar 23, 2017, 7:44:54 AM3/23/17
to Gremlin-users
We really don't have a way to do what you're after directly. When you put the console in remote console mode and issue commands they just get sent as strings directly to the server to be evaluated there. so doing something like this:

gremlin> x = 1
==>1
gremlin> :> g.V(x)

will just error out as your "x" variable just stays local. I've often thought about providing a way to export variables from the console to the server with a new command or something, but I dunno....

just a thought though, i think we'd want to not replicate the entire set of local variables to the server as that could lead to confusion and problems. It would likely be an explicit command, perhaps something like:

:remote config export x

I guess if you'd like to see something like that you could open a ticket for consideration.


--
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-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/7829f931-1ace-4d70-a6e1-ba267027ef13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kevin Gallardo

unread,
Mar 23, 2017, 11:52:23 AM3/23/17
to Gremlin-users
I think it should work out of the box with a remote traversal source configured, the List would be sent as part of the Traversal's Bytecode and the server would read it as part of the request. Seems to be working for me. 

Also, using the gremlin-driver directly (which can be used from within the console), the list of variables could be sent as a parameter of the query. e.g.:

Map variables = new HashMap();
variables
.put("userNames", userNames);
client
.submit("g.V().has('userName', within(userNames)).out('bought').values('productName').dedup()", variables);

However, the size of the list if the file is big could create too big requests.

As Stephen said there's no direct way to "save" a variable on the server, but one way currently to do it, and avoid sending the list for each query if the list is not meant to change over time, would be to use a gremlin-driver's Client with a stateful session:
gremlin> cluster = Cluster.open();
==>localhost/127.0.0.1:8182
gremlin
> client = cluster.connect("sessionMl") // the name of the session doesn't matter as long as it's the same reused later in the ":remote" command
==>org.apache.tinkerpop.gremlin.driver.Client$SessionedClient@3a4ba480
gremlin
> userNamesLocalVar = [... load the user names from the file ...]
{...}
gremlin
> client.submit('userNames = userNamesParam', ['userNamesParam':userNamesLocalVar])
==>result{obj ... }
==>...
gremlin
> :remote connect tinkerpop.server conf/remote.yaml session sessionMl
gremlin
> :> g.V().has("name", within(userNames)) // should work

Hope that helps.

On Thursday, March 23, 2017 at 7:44:54 AM UTC-4, Stephen Mallette wrote:
We really don't have a way to do what you're after directly. When you put the console in remote console mode and issue commands they just get sent as strings directly to the server to be evaluated there. so doing something like this:

gremlin> x = 1
==>1
gremlin> :> g.V(x)

will just error out as your "x" variable just stays local. I've often thought about providing a way to export variables from the console to the server with a new command or something, but I dunno....

just a thought though, i think we'd want to not replicate the entire set of local variables to the server as that could lead to confusion and problems. It would likely be an explicit command, perhaps something like:

:remote config export x

I guess if you'd like to see something like that you could open a ticket for consideration.

On Tue, Mar 21, 2017 at 11:35 AM, Florian Hockmann <f...@florian-hockmann.de> wrote:
Hi,

I am often working with a file that contains data which I want to use as a starting point for a traversal. So something like this:
userNames = new ArrayList<String>()
new File('myUsernames.txt').eachLine{ line -> userNames.add(line)}
g
.V().has('userName', within(userNames)).out('bought').values('productName').dedup()

This is of course just an example. The point is that I want to use the Gremlin Console to connect to a remote Gremlin Server and execute a traversal that uses data from my local machine (stored in the variable userNames in the example above).

I have no problem doing this when I use the Gremlin Console on the same machine Gremlin Server is running on, but I don't know how to send the data over a remote connection. Is there any way to do this?

Regards,
Florian

--
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.

Florian Hockmann

unread,
Mar 28, 2017, 8:17:02 AM3/28/17
to Gremlin-users
Thanks for your suggestions on this. The option to use a remote traversal source looks very promising, especially as it doesn't require any special treatment for the local variable. Wouldn't it make sense in general to use a remote traversal source as the default option when connecting via console to a remote server? This would reduce the differences between working in the console and in Java or Python for example and it would also simplify the console as the remote options aren't needed anymore.
Reply all
Reply to author
Forward
0 new messages