【问题标题】:Titan -> Neo4j Gremlin subgraphTitan -> Neo4j Gremlin 子图
【发布时间】:2023-10-07 06:55:01
【问题描述】:

我希望提取所有附加到特定列表的边和顶点以及它们跟随的人,并将它们直接复制到 neo4j,或者通过创建数据的 graphson 或 kryo 文件。

类似的东西:

g.V().has("sublist_id", 14).in('ON').out('FOLLOWS')

我基本上希望单独的数据库或文件中的每个顶点和边单独查询。

我最好的方法是什么?

我执行了以下操作,但似乎无法导出为 json 或 kryo only graphml。

gremlin> subGraph = g.V().has('sublist_id', 14).in('ON').outE('FOLLOWS').subgraph('subGraph').cap('subGraph').next()
==>tinkergraph[vertices:3438716 edges:14090945]


gremlin> subGraph.io(IoCore.gryo()).writeGraph("/data/test.kryo")
Class is not registered: com.thinkaurelius.titan.graphdb.relations.RelationIdentifier
Note: To register this class use: kryo.register(com.thinkaurelius.titan.graphdb.relations.RelationIdentifier.class);
Display stack trace?


gremlin> subGraph.io(IoCore.graphson()).writeGraph("/data/test.json");
(was java.lang.IllegalStateException) (through reference chain: com.thinkaurelius.titan.graphdb.relations.RelationIdentifier["inVertexId"])
Display stack trace? [yN]

【问题讨论】:

    标签: titan gremlin tinkerpop3


    【解决方案1】:

    当您从一个图生成子图并尝试推送到另一个图时,您最终可能会遇到序列化问题,因为新图可能不知道如何处理第一个图中的数据。这就是您在这里遇到的情况,特别是 RelationIdentifier,它是 Titan 中的唯一 ID。

    因此,在您的工作上下文中,您有一个 TinkerGraph,其中包含 Titan RelationIdentifier,当您将其写入 gryo 时,序列化过程失败,因为 TinkerGraph 不了解 Titan序列化器。

    您可以通过为 gryo 提供 Titan 序列化程序来解决此问题。执行以下操作:

    gryo = GryoIo.build().registry(TitanIoRegistry.INSTANCE).graph(subGraph).create()
    gryo.writeGraph("/data/test.kryo")
    

    这是一种方法。您还可以从头开始构建GryoWriter,以更好地控制不同的选项和设置。

    【讨论】: