gpt4 book ai didi

gremlin - 使用 Gremlin 将 Tinkergraph SubGraph 导出到文件

转载 作者:行者123 更新时间:2023-12-04 09:39:28 27 4
gpt4 key购买 nike

使用 JanusGraph 和 Gremlin,我有一个似乎失败的图形导出要求。从 Gremlin 控制台,我可以导出我的小图:
g.io('sample.json').write().iterate()成功地。 g==>graphtraversalsource[standardjanusgraph[berkeleyje:/var/lib/janusgraph/data], standard]

现在我想对子图做同样的事情,所以从 gremlin 控制台,我生成了一个 tingergraph,如下所示:

gremlin> sn_graph = g.V().hasLabel('rule').repeat(bothE().subgraph('sample').otherV()).times(3).cap('sample').next()
==>tinkergraph[vertices:285 edges:276]
gremlin> sg = sn_graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:285 edges:276], standard]
gremlin> sg.io('/tmp/sample.json').write().iterate()
org.apache.tinkerpop.gremlin.jsr223.console.RemoteException

我希望我能够将我的子图导出到文件中,就像我能够导出我的原始图一样 g .但我一直在运行一个异常(exception)。我觉得唯一的区别是一个基于 berkeleyje,另一个是 tinkergraph。
java.lang.IllegalStateException
at com.google.common.base.Preconditions.checkState(Preconditions.java:158)
at org.janusgraph.graphdb.relations.RelationIdentifier.getInVertexId(RelationIdentifier.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tinkerpop.shaded.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:688)
at org.apache.tinkerpop.shaded.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719)
at org.apache.tinkerpop.shaded.jackson.databind.ser.std.BeanSerializerBase.serializeWithType(BeanSerializerBase.java:604)
at org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONUtil.writeWithType(GraphSONUtil.java:51)
at org.apache.tinkerpop.gremlin.structure.util.star.StarGraphGraphSONSerializerV2d0.ser(StarGraphGraphSONSerializerV2d0.java:89)
at org.apache.tinkerpop.gremlin.structure.util.star.StarGraphGraphSONSerializerV2d0.serializeWithType(StarGraphGraphSONSerializerV2d0.java:65)
at org.apache.tinkerpop.gremlin.structure.util.star.StarGraphGraphSONSerializerV2d0.serializeWithType(StarGraphGraphSONSerializerV2d0.java:48)
at org.apache.tinkerpop.shaded.jackson.databind.ser.impl.TypeWrappedSerializer.serialize(TypeWrappedSerializer.java:32)
at org.apache.tinkerpop.shaded.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
at org.apache.tinkerpop.shaded.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
at org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3905)
at org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:3176)
at org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter.writeVertex(GraphSONWriter.java:82)
at org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter.writeVertices(GraphSONWriter.java:110)
at org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter.writeGraph(GraphSONWriter.java:71)
at org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IoStep.write(IoStep.java:121)
at org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IoStep.processNextStart(IoStep.java:112)
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143)
at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:50)
at org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep.processNextStart(FilterStep.java:37)
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.next(AbstractStep.java:128)
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.next(AbstractStep.java:38)
at org.apache.tinkerpop.gremlin.process.traversal.Traversal.iterate(Traversal.java:203)
at org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal.iterate(GraphTraversal.java:2862)
at org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal$Admin.iterate(GraphTraversal.java:187)
at org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal.iterate(DefaultGraphTraversal.java:48)
at org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal$Admin$iterate.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:119)
at Script205.run(Script205.groovy:1)
at org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.eval(GremlinGroovyScriptEngine.java:674)
at org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.eval(GremlinGroovyScriptEngine.java:376)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)
at org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.lambda$eval$0(GremlinExecutor.java:266)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)



我似乎无法弄清楚我在这里缺少什么。任何帮助表示赞赏!

最佳答案

您的 TinkerGraph 包含 JanusGraph 标识符 - RelationIdentifier - GraphSON 不知道如何序列化它。您需要提供 JanusGraph GraphSON 序列化程序,如下所述 here :

file = new FileOutputStream("/tmp/sample.json")
mapper = GraphSONMapper.build().addCustomModule(org.janusgraph.graphdb.tinkerpop.io.graphson.JanusGraphSONModuleV2d0.getInstance()).create()
writer = GraphSONWriter.build().mapper(mapper).create()
writer.writeGraph(file, sg)
上述方法使用 GraphSONWriter直接,但您也可以将其交给 io()步骤,因为您通过 Gremlin 控制台发送脚本:
sg.io('/tmp/sample.json').
with(IO.registry, JanusGraphIoRegistry.getInstance()).
write().iterate()

关于gremlin - 使用 Gremlin 将 Tinkergraph SubGraph 导出到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62397436/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com