I put the example vertex GraphSON of a g:Vertex
in a file:
$ cat vertex.json
{ "@type" : "g:Vertex", "@value" : { "id" : { "@type" : "g:Int32", "@value" : 1 }, "label" : "person", "properties" : { "name" : [ { "@type" : "g:VertexProperty", "@value" : { "id" : { "@type" : "g:Int64", "@value" : 0 }, "value" : "marko", "label" : "name" } } ], "location" : [ { "@type" : "g:VertexProperty", "@value" : { "id" : { "@type" : "g:Int64", "@value" : 6 }, "value" : "san diego", "label" : "location", "properties" : { "startTime" : { "@type" : "g:Int32", "@value" : 1997 }, "endTime" : { "@type" : "g:Int32", "@value" : 2001 } } } }, { "@type" : "g:VertexProperty", "@value" : { "id" : { "@type" : "g:Int64", "@value" : 7 }, "value" : "santa cruz", "label" : "location", "properties" : { "startTime" : { "@type" : "g:Int32", "@value" : 2001 }, "endTime" : { "@type" : "g:Int32", "@value" : 2004 } } } }, { "@type" : "g:VertexProperty", "@value" : { "id" : { "@type" : "g:Int64", "@value" : 8 }, "value" : "brussels", "label" : "location", "properties" : { "startTime" : { "@type" : "g:Int32", "@value" : 2004 }, "endTime" : { "@type" : "g:Int32", "@value" : 2005 } } } }, { "@type" : "g:VertexProperty", "@value" : { "id" : { "@type" : "g:Int64", "@value" : 9 }, "value" : "santa fe", "label" : "location", "properties" : { "startTime" : { "@type" : "g:Int32", "@value" : 2005 } } } } ] } } }
Trying to read it into Python Gremlin Server:
from gremlin_python.process.anonymous_traversal import traversal
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
g = traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
g.io("/home/ubuntu/vertex.json").read().iterate()
yields an error:
GremlinServerError: 500: org.apache.tinkerpop.shaded.jackson.databind.JsonMappingException: Could not deserialize the JSON value as required. Nested exception: java.lang.InstantiationException: Cannot deserialize the value with the detected type contained in the JSON ('g:Vertex') to the type specified in parameter to the object mapper (interface java.util.Map). Those types are incompatible. at [Source: (ByteArrayInputStream); line: 1, column: 36]
I've tried messing with the graphson_reader
and message_serializer
parameters of DriverRemoteConnection
to specify GraphSONSerializersV3d0
but I can't get past that error.
How can the example vertex GraphSON above be read into a graph from Python's Gremlin Server?
How did you create the GraphSON? It might be worth using TinkerGraph to create a simple GraphSON file and comparing yours to that to make sure you have the syntax correct. I used the steps below to create the JSON also shown below. The GraphSON in your example looks more like a query result than a file describing a graph. Anyway here is an example:
gremlin> g.addV('test').property('name','some-name').property('age','some-age')
==>v[61015]
gremlin> g.io('test.json').write()
{"id":{"@type":"g:Int64","@value":61015},"label":"test","properties":{"name":[{"id":{"@type":"g:Int64","@value":61016},"value":"some-name"}],"age":[{"id":{"@type":"g:Int64","@value":61017},"value":"some-age"}]}}
Here is a link to the Apache TinkerPop GraphSON reference documentation.