Hi,

Whilst optimizing the NotStep I came across what looks to me like a bug in TraversalHelper.replaceStep or perhaps rather in CountStrategy.

The test below shows the bug.

    @Test
    public void g_VX1X_repeatXoutX_untilXoutE_count_isX0XX_name() {
        Graph graph = TinkerFactory.createModern();
        final Traversal<Vertex, String> traversal1 = graph.traversal()
                .V(convertToVertexId(graph, "marko"))
                .repeat(__.out())
                .until(__.not(__.outE()))
                .values("name");
        checkResults(Arrays.asList("lop", "lop", "ripple", "vadas"), traversal1);

        List<VertexStep> vertexSteps = TraversalHelper.getStepsOfAssignableClassRecursively(VertexStep.class, traversal1.asAdmin());         VertexStep vertexStep = vertexSteps.stream().filter(s -> s.returnsEdge()).findAny().get();         Assert.assertEquals(EmptyStep.instance(), vertexStep.getPreviousStep());

        final Traversal<Vertex, String> traversal2 = graph.traversal()
                .V(convertToVertexId(graph, "marko"))
                .repeat(__.out())
                .until(__.outE().count().is(0))
                .values("name");
        checkResults(Arrays.asList("lop", "lop", "ripple", "vadas"), traversal2);

        vertexSteps = TraversalHelper.getStepsOfAssignableClassRecursively(VertexStep.class, traversal2.asAdmin());         vertexStep = vertexSteps.stream().filter(s -> s.returnsEdge()).findAny().get();

        //This fails because the vertexStep's previous step is the NotStepwhen it should be an EmptyStep.         Assert.assertEquals(EmptyStep.instance(), vertexStep.getPreviousStep());
    }

traversal1 and traversal2 should be the same as the CountStrategy will replace the __.outE().count().is(0) with __.not(__.outE()) The CountStrategy does what its suppose to do however then it calls TraversalHelper.replaceStep(prev, new NotStep<>(traversal, inner), traversal); the traversal's VertexStep gets its previousStep set to the NotStep. This is because of the way TraversalHelper.replaceStep is implemented.

I am not sure whether the fix should be in replaceStep or rather in CountStrategy.

Thanks
Pieter

Reply via email to