Print GraphSON in Gremlin Console for graph hosted by Gremlin Server

238 views
Skip to first unread message

Tanner Sorensen

unread,
Jan 6, 2022, 4:13:20 PM1/6/22
to Gremlin-users
I am familiar with how to print the output of a Gremlin query as GraphSON in the Gremlin Console.

gremlin> graph = TinkerFactory.createModern()
==>tinkergraph[vertices:6 edges:6]
gremlin> g = traversal().withEmbedded(graph)
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> mapper = GraphSONMapper.build().version(GraphSONVersion.V3_0).create().createMapper()
==>org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper@307e4c44
gremlin> v = g.V().has('name','marko').valueMap(true).next()
==>id=1
==>label=person
==>name=[marko]
==>age=[29]
gremlin> mapper.writeValueAsString(v)
==>{"@type":"g:Map","@value":[{"@type":"g:T","@value":"id"},{"@type":"g:Int32","@value":1},{"@type":"g:T","@value":"label"},"person","name",{"@type":"g:List","@value":["marko"]},"age",{"@type":"g:List","@value":[{"@type":"g:Int32","@value":29}]}]}

However, when I try the same for a graph hosted on a Gremlin Server, I get an error:

gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Configured localhost/127.0.0.1:8182
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8182] - type ':remote console' to return to local mode
gremlin> mapper = GraphSONMapper.build().version(GraphSONVersion.V3_0).create().createMapper()
==>org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper@4690357f
gremlin> v = g.V().has('name','marko').valueMap(true).next()
==>id=1
==>label=person
==>name=[marko]
==>age=[29]
gremlin> mapper.writeValueAsString(v)
No such property: mapper for class: Script6
Type ':help' or ':h' for help.
Display stack trace? [yN]y
groovy.lang.MissingPropertyException: No such property: mapper for class: Script6
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:65)
        at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:51)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:309)
        at Script6.run(Script6.groovy:1)
        at org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.eval(GremlinGroovyScriptEngine.java:676)
        at org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.eval(GremlinGroovyScriptEngine.java:378)
        at java.scripting/javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)
        at org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.lambda$eval$0(GremlinExecutor.java:272)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)

Have I misconfigured the Gremlin Server? My Gremlin Server config is the following:

host: localhost
port: 8182
evaluationTimeout: 30000
graphs: {
  graph: conf/tinkergraph-empty.properties}
scriptEngines: {
  gremlin-groovy: {
    plugins: { org.apache.tinkerpop.gremlin.server.jsr223.GremlinServerGremlinPlugin: {},
               org.apache.tinkerpop.gremlin.tinkergraph.jsr223.TinkerGraphGremlinPlugin: {},
               org.apache.tinkerpop.gremlin.groovy.jsr223.GroovyCompilerGremlinPlugin: {enableThreadInterrupt: true},
               org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: {classImports: [java.lang.Math], methodImports: [java.lang.Math#*]},
               org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: {files: [scripts/generate-modern.groovy]}}}}
serializers:
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV3d0] }}        # application/json
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1 }                                                                                                           # application/vnd.graphbinary-v1.0
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1, config: { serializeResultToString: true }}                                                                 # application/vnd.graphbinary-v1.0-stringd
metrics: {
  slf4jReporter: {enabled: true, interval: 180000}}
strictTransactionManagement: false
idleConnectionTimeout: 0
keepAliveInterval: 0
maxInitialLineLength: 4096
maxHeaderSize: 8192
maxChunkSize: 8192
maxContentLength: 65536
maxAccumulationBufferComponents: 1024
resultIterationBatchSize: 64

Stephen Mallette

unread,
Jan 7, 2022, 6:59:17 AM1/7/22
to gremli...@googlegroups.com
You need to connect the console with a session or else "mapper" state won't be preserved to the next request:


--
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/4dcb1f11-64ce-44f7-8ecb-c83b13f1a8bbn%40googlegroups.com.

Tanner Sorensen

unread,
Jan 7, 2022, 10:42:10 AM1/7/22
to Gremlin-users
Oh, great. Works as expected. Thank you!

gremlin> :remote connect tinkerpop.server conf/remote.yaml session
==>Configured localhost/127.0.0.1:8182-[925fea72-3325-4cb3-8c6d-130c0761c048]
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8182]-[925fea72-3325-4cb3-8c6d-130c0761c048] - type ':remote console' to return to local mode
gremlin> mapper = GraphSONMapper.build().version(GraphSONVersion.V3_0).create().createMapper()
==>org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper@3f7ba679

gremlin> v = g.V().has('name','marko').valueMap(true).next()
==>id=1
==>label=person
==>name=[marko]
==>age=[29]
gremlin> mapper.writeValueAsString(v)
==>{"@type":"g:Map","@value":[{"@type":"g:T","@value":"id"},{"@type":"g:Int64","@value":1},{"@type":"g:T","@value":"label"},"person","name",{"@type":"g:List","@value":["marko"]},"age",{"@type":"g:List","@value":[{"@type":"g:Int32","@value":29}]}]}
Reply all
Reply to author
Forward
0 new messages