Gremlin Console Save

1,135 views
Skip to first unread message

Hammad Ali Khan

unread,
Nov 20, 2018, 3:42:32 AM11/20/18
to Gremlin-users
Hi all,
I was using :record to save data in a txt file btw I am using AWS Neptune. After recording to file I get following output:

// OPENED: Tue Nov 20 13:08:14 PKT 2018
// RESULT: mylog.txt
g.V().hasLabel("Sub-Class").count().next()
// RESULT: java.util.Spliterators$1Adapter@5d71b500
:record start mylog.txt
:record stop
// CLOSED: Tue Nov 20 13:08:27 PKT 2018

and if there is any export method to save in csv or other prettier file format.

Regards,
HAK

Stephen Mallette

unread,
Nov 20, 2018, 6:58:39 AM11/20/18
to gremli...@googlegroups.com
Not sure why :record is giving you a toString() representation for count() - works for me just fine. If you're after getting CSV format, i'd just use Groovy to write to file directly:

gremlin> output = new File("out.txt")
==>out.txt
gremlin> g.V().hasLabel("person").valueMap().by(unfold()).each{output.append("${it.name}\t${it.age}\r\n")}

That generates a pretty simple CSV on 3.4.0-SNAPSHOT. Of course, as I get this far writing I realize that you're on Neptune so you only have :remote graph to talk to in which case this doesn't work quite as nicely. as you can't stream the result right into a local file. You'd have to do:

:remote connect tinkerpop.server conf/neptune-remote.yaml

where serializeResultToString is set to false (or not set at all) and then you do 

gremlin> output = new File("out.txt")
==>out.txt
gremlin> :> g.V().hasLabel("person").valueMap().by(unfold())

The result of :> will be stored in a local variable named "result" which you can then iterate yourself into a CSV.





--
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/d82c5a32-e80f-4d12-91f9-c8e3f624c21c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hammad Ali Khan

unread,
Nov 20, 2018, 7:57:00 AM11/20/18
to Gremlin-users
gremlin> :record start sub.txt
Recording session to: "sub.txt"
==>sub.txt
gremlin> g.V().count().toString()
==>317159
gremlin> :record stop
Recording stopped; session saved as: "sub.txt" (178 bytes)
==>sub.txt
gremlin> out = new File("output.txt")
{"requestId":"013029c8-b914-4867-b780-5fd5a03c87cd","code":"MalformedQueryException","detailedMessage":"Query parsing failed at line 1, character position at 4, error message : token recognition error at: '='"}
Type ':help' or ':h' for help.
Display stack trace? [yN]uy
gremlin> out = new File("output.txt")
{"requestId":"64756f4d-2251-4164-a696-4106352a0168","code":"MalformedQueryException","detailedMessage":"Query parsing failed at line 1, character position at 4, error message : token recognition error at: '='"}
Type ':help' or ':h' for help.
Display stack trace? [yN]y
org.apache.tinkerpop.gremlin.jsr223.console.RemoteException: {"requestId":"64756f4d-2251-4164-a696-4106352a0168","code":"MalformedQueryException","detailedMessage":"Query parsing failed at line 1, character position at 4, error message : token recognition error at: '='"}
at org.apache.tinkerpop.gremlin.console.jsr223.DriverRemoteAcceptor.submit(DriverRemoteAcceptor.java:178)
at org.apache.tinkerpop.gremlin.console.GremlinGroovysh.execute(GremlinGroovysh.groovy:99)
at org.codehaus.groovy.tools.shell.Shell.leftShift(Shell.groovy:122)
at org.codehaus.groovy.tools.shell.InteractiveShellRunner.super$2$work(InteractiveShellRunner.groovy)
at jdk.internal.reflect.GeneratedMethodAccessor32.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1225)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:145)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:165)
at org.codehaus.groovy.tools.shell.ShellRunner.run(ShellRunner.groovy:59)
at org.codehaus.groovy.tools.shell.InteractiveShellRunner.super$2$run(InteractiveShellRunner.groovy)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1225)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:145)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:165)
at org.codehaus.groovy.tools.shell.InteractiveShellRunner.run(InteractiveShellRunner.groovy:89)
at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:236)
at org.apache.tinkerpop.gremlin.console.Console.<init>(Console.groovy:146)
at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:236)
at org.apache.tinkerpop.gremlin.console.Console.main(Console.groovy:453)

sub.txt has same output as before and File creation returns above error..
Regards,
HAK 

Stephen Mallette

unread,
Nov 20, 2018, 8:02:39 AM11/20/18
to gremli...@googlegroups.com
I don't think you followed my instructions exactly....I assume that you executed this command:

:remote console

If you do that it will put the Gremlin Console in a state where everything you type will be evaluated on the server. You want to evaluate your scripts locally unless you explicitly say otherwise with the submit command :>. I also suggested you stay away from the :record command as it is unecessary for writing to file - you're doing that already with the File object you're opening. 

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

Hammad Ali Khan

unread,
Nov 20, 2018, 8:13:38 AM11/20/18
to Gremlin-users
Yes you were right thank alot.

Kelvin Lawrence

unread,
Nov 21, 2018, 3:22:23 PM11/21/18
to Gremlin-users
FWIW - I see the same // RESULT: java.util.Spliterators$1Adapter if the query is sent to a Gremlin Server.

So if you just do this:


gremlin> :record start mylog.txt
gremlin
> :> g.V().count()
gremlin
> :record stop

catmylog
.txt

// OPENED: Wed Nov 21 14:14:06 CST 2018
// RESULT: mylog.txt
:> g.V().count()
// RESULT: java.util.Spliterators$1Adapter@7048535f
:record stop
// CLOSED: Wed Nov 21 14:14:32 CST 2018


This was using a vanilla Gremlin Server running TinkerGraph

Is this even expected to work when using a Gremlin Server? To be honest I have only ever used :record when working with a local TinkerGraph.

Cheers
Kelvin

Stephen Mallette

unread,
Nov 21, 2018, 3:49:16 PM11/21/18
to gremli...@googlegroups.com
not sure that :remote commands are going to work in Gremlin Server given some of the magic happening behind the scenes..........made a note to update documentation around that.

Reply all
Reply to author
Forward
0 new messages