Как добавить g: Vertex GraphSON в Python Gremlin? - PullRequest
2 голосов
/ 10 апреля 2020

Я помещаю пример вершины GraphSON из g:Vertex в файл:

$ 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 } } } } ] } } }

Пытаясь прочитать его на Python Сервер Gremlin:

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()                                                                                                                                                                       

выдает ошибку:

GremlinServerError: 500: org. apache .tinkerpop.shaded.jackson.databind.JsonMappingException: Не удалось десериализовать значение JSON, как требуется. Вложенное исключение: java .lang.InstantiationException: Невозможно десериализовать значение с обнаруженным типом, содержащимся в JSON ('g: Vertex'), в тип, указанный в параметре для сопоставителя объектов (интерфейс java .util. Карта). Эти типы несовместимы. в [Source: (ByteArrayInputStream); строка: 1, столбец: 36]

Я пытался связываться с параметрами graphson_reader и message_serializer DriverRemoteConnection, чтобы указать GraphSONSerializersV3d0, но не могу обойти эту ошибку ,

Как можно прочитать приведенную выше примерную вершину GraphSON в графе с сервера Python Gremlin?

1 Ответ

3 голосов
/ 10 апреля 2020

Как вы создали GraphSON? Возможно, стоит использовать TinkerGraph для создания простого файла GraphSON и сравнить его с этим, чтобы убедиться в правильности синтаксиса. Я использовал шаги ниже, чтобы создать JSON, также показанный ниже. GraphSON в вашем примере больше похож на результат запроса, чем на файл, описывающий график. В любом случае, вот пример:

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"}]}}

Вот ссылка на справочную документацию Apache TinkerPop GraphSON.

http://tinkerpop.apache.org/docs/3.4.6/dev/io/#graphson

...