I have a traversal where I need to repeat till no more new edges are found. In gremlin console/groovy I achieve this by passing a lambda that always returns false.
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'))
When I try the same approach from a Java application and connect to an AWS Neptune instance, I get an exception stating that the command cant be sent to server ...
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")));
I understand, I need to register Java Lambda, and maybe Predicates as serializable, but couldn't figure out the syntax. Also how do I add it to my cluster builder using "serializer" ?
The full stack trace :
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$34/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$34/1735507635 Note: To register this class use: kryo.register(org.saswata.Main$$Lambda$34/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.access$1900(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$5.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$34/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$34/1735507635 Note: To register this class use: kryo.register(org.saswata.Main$$Lambda$34/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
Meanwhile I have side stepped the issue using a hack to check for a non existent label in the until argument hasLabel('fake')
As you can see HERE Neptune doesn't support lambdas steps. So you can't use this type of syntax.
Also in your use-case, you don't need the until
step at all. if you don't use it, the repeat
step will continue until it reaches an empty traversal.
example: https://gremlify.com/8es7aelrr4n