TinkerPop Gremlin How to serialize Predicate passed in Until 步骤
TinkerPop Gremlin How to serealize Predicate passed in Until step
我有一个遍历,我需要重复遍历直到找不到更多新边。在 gremlin console/groovy 中,我通过传递一个始终 returns false.
的 lambda 来实现这一点
g.V(7).
repeat(out().not(hasLabel('region', 'business')).simplePath()).
until(outE().count().is(0)).
repeat(both().not(hasLabel('region', 'business')).dedup()).
emit().until{t -> false}.
where(hasLabel('account'))
当我从 Java 应用程序尝试相同的方法并连接到 AWS Neptune 实例时,我收到一个异常,指出无法将命令发送到服务器 ...
GraphTraversal t =
g.V(uid).union(__.identity(),
__.repeat(__.out().not(__.hasLabel("region", "business")).simplePath()).
until(__.outE().limit(1).count().is(0)).
repeat(__.both().not(__.hasLabel("region", "business")).simplePath()).
until(x -> false).emit(__.hasLabel("account")));
我明白了,我需要注册 Java Lambda,也许 Predicates 是可序列化的,但无法弄清楚语法。另外,如何使用“serializer”将它添加到我的集群构建器中?
完整的堆栈跟踪:
Exception in thread "main" io.netty.handler.codec.EncoderException:
org.apache.tinkerpop.gremlin.driver.exception.ResponseException: An
error occurred during serialization of this request [RequestMessage{,
requestId=28cd3e32-306a-457e-a6d2-2dc5bc9797d8, op='bytecode',
processor='traversal', args={gremlin=[[], [V(A_639008103873),
union([[], [identity()]], [[], [repeat([[], [out(), not([[],
[hasLabel(region, business)]]), simplePath()]]), until([[], [outE(),
limit(1), count(), is(0)]]), repeat([[], [both(), not([[],
[hasLabel(region, business)]]), simplePath()]]),
until(org.saswata.Main$$Lambda/1735507635@6110020d), emit([[],
[hasLabel(aws_account)]])]])]], aliases={g=g}}}] - it could not be
sent to the server - Reason:
org.apache.tinkerpop.gremlin.driver.ser.SerializationException:
java.lang.IllegalArgumentException: Class is not registered:
org.saswata.Main$$Lambda/1735507635 Note: To register this class
use: kryo.register(org.saswata.Main$$Lambda/1735507635.class); at
io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:106)
at
io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738)
at
io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:730)
at
io.netty.channel.AbstractChannelHandlerContext.access00(AbstractChannelHandlerContext.java:38)
at
io.netty.channel.AbstractChannelHandlerContext$AbstractWriteTask.write(AbstractChannelHandlerContext.java:1081)
at
io.netty.channel.AbstractChannelHandlerContext$WriteAndFlushTask.write(AbstractChannelHandlerContext.java:1128)
at
io.netty.channel.AbstractChannelHandlerContext$AbstractWriteTask.run(AbstractChannelHandlerContext.java:1070)
at
io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at
io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:465) at
io.netty.util.concurrent.SingleThreadEventExecutor.run(SingleThreadEventExecutor.java:884)
at java.lang.Thread.run(Thread.java:748) Caused by:
org.apache.tinkerpop.gremlin.driver.exception.ResponseException: An
error occurred during serialization of this request [RequestMessage{,
requestId=28cd3e32-306a-457e-a6d2-2dc5bc9797d8, op='bytecode',
processor='traversal', args={gremlin=[[], [V(A_639008103873),
union([[], [identity()]], [[], [repeat([[], [out(), not([[],
[hasLabel(region, business)]]), simplePath()]]), until([[], [outE(),
limit(1), count(), is(0)]]), repeat([[], [both(), not([[],
[hasLabel(region, business)]]), simplePath()]]),
until(org.saswata.Main$$Lambda/1735507635@6110020d), emit([[],
[hasLabel(aws_account)]])]])]], aliases={g=g}}}] - it could not be
sent to the server - Reason:
org.apache.tinkerpop.gremlin.driver.ser.SerializationException:
java.lang.IllegalArgumentException: Class is not registered:
org.saswata.Main$$Lambda/1735507635 Note: To register this class
use: kryo.register(org.saswata.Main$$Lambda/1735507635.class); at
org.apache.tinkerpop.gremlin.driver.handler.WebSocketGremlinRequestEncoder.encode(WebSocketGremlinRequestEncoder.java:63)
at
org.apache.tinkerpop.gremlin.driver.handler.WebSocketGremlinRequestEncoder.encode(WebSocketGremlinRequestEncoder.java:40)
at
io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:88)
... 11 more
与此同时,我使用 hack 来检查 until 参数中是否存在不存在的标签,从而解决了这个问题 hasLabel('fake')
如您所见HERE Neptune 不支持 lambdas 步骤。
所以你不能使用这种语法。
同样在您的用例中,您根本不需要 until
步骤。如果你不使用它,repeat
步骤将继续直到它到达空遍历。
我有一个遍历,我需要重复遍历直到找不到更多新边。在 gremlin console/groovy 中,我通过传递一个始终 returns false.
的 lambda 来实现这一点g.V(7).
repeat(out().not(hasLabel('region', 'business')).simplePath()).
until(outE().count().is(0)).
repeat(both().not(hasLabel('region', 'business')).dedup()).
emit().until{t -> false}.
where(hasLabel('account'))
当我从 Java 应用程序尝试相同的方法并连接到 AWS Neptune 实例时,我收到一个异常,指出无法将命令发送到服务器 ...
GraphTraversal t =
g.V(uid).union(__.identity(),
__.repeat(__.out().not(__.hasLabel("region", "business")).simplePath()).
until(__.outE().limit(1).count().is(0)).
repeat(__.both().not(__.hasLabel("region", "business")).simplePath()).
until(x -> false).emit(__.hasLabel("account")));
我明白了,我需要注册 Java Lambda,也许 Predicates 是可序列化的,但无法弄清楚语法。另外,如何使用“serializer”将它添加到我的集群构建器中?
完整的堆栈跟踪:
Exception in thread "main" io.netty.handler.codec.EncoderException: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: An error occurred during serialization of this request [RequestMessage{, requestId=28cd3e32-306a-457e-a6d2-2dc5bc9797d8, op='bytecode', processor='traversal', args={gremlin=[[], [V(A_639008103873), union([[], [identity()]], [[], [repeat([[], [out(), not([[], [hasLabel(region, business)]]), simplePath()]]), until([[], [outE(), limit(1), count(), is(0)]]), repeat([[], [both(), not([[], [hasLabel(region, business)]]), simplePath()]]), until(org.saswata.Main$$Lambda/1735507635@6110020d), emit([[], [hasLabel(aws_account)]])]])]], aliases={g=g}}}] - it could not be sent to the server - Reason: org.apache.tinkerpop.gremlin.driver.ser.SerializationException: java.lang.IllegalArgumentException: Class is not registered: org.saswata.Main$$Lambda/1735507635 Note: To register this class use: kryo.register(org.saswata.Main$$Lambda/1735507635.class); at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:106) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:730) at io.netty.channel.AbstractChannelHandlerContext.access00(AbstractChannelHandlerContext.java:38) at io.netty.channel.AbstractChannelHandlerContext$AbstractWriteTask.write(AbstractChannelHandlerContext.java:1081) at io.netty.channel.AbstractChannelHandlerContext$WriteAndFlushTask.write(AbstractChannelHandlerContext.java:1128) at io.netty.channel.AbstractChannelHandlerContext$AbstractWriteTask.run(AbstractChannelHandlerContext.java:1070) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:465) at io.netty.util.concurrent.SingleThreadEventExecutor.run(SingleThreadEventExecutor.java:884) at java.lang.Thread.run(Thread.java:748) Caused by: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: An error occurred during serialization of this request [RequestMessage{, requestId=28cd3e32-306a-457e-a6d2-2dc5bc9797d8, op='bytecode', processor='traversal', args={gremlin=[[], [V(A_639008103873), union([[], [identity()]], [[], [repeat([[], [out(), not([[], [hasLabel(region, business)]]), simplePath()]]), until([[], [outE(), limit(1), count(), is(0)]]), repeat([[], [both(), not([[], [hasLabel(region, business)]]), simplePath()]]), until(org.saswata.Main$$Lambda/1735507635@6110020d), emit([[], [hasLabel(aws_account)]])]])]], aliases={g=g}}}] - it could not be sent to the server - Reason: org.apache.tinkerpop.gremlin.driver.ser.SerializationException: java.lang.IllegalArgumentException: Class is not registered: org.saswata.Main$$Lambda/1735507635 Note: To register this class use: kryo.register(org.saswata.Main$$Lambda/1735507635.class); at org.apache.tinkerpop.gremlin.driver.handler.WebSocketGremlinRequestEncoder.encode(WebSocketGremlinRequestEncoder.java:63) at org.apache.tinkerpop.gremlin.driver.handler.WebSocketGremlinRequestEncoder.encode(WebSocketGremlinRequestEncoder.java:40) at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:88) ... 11 more
与此同时,我使用 hack 来检查 until 参数中是否存在不存在的标签,从而解决了这个问题 hasLabel('fake')
如您所见HERE Neptune 不支持 lambdas 步骤。 所以你不能使用这种语法。
同样在您的用例中,您根本不需要 until
步骤。如果你不使用它,repeat
步骤将继续直到它到达空遍历。