[
https://issues.apache.org/jira/browse/TINKERPOP3-949?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15007222#comment-15007222
]
pieter martin commented on TINKERPOP3-949:
------------------------------------------
Ok, so back to the issue.
you write,
{noformat}
g.V(a1).emit().repeat(__.out()).times(3).path()
{noformat}
"Well, you emit, then you out, and then you ask "have you been repeated 3
times?"
But you don't, this is do while semantics, not while do.
So you should ask have you been repeated 4 times.
>From the docs,
>[http://tinkerpop.incubator.apache.org/docs/3.0.2-incubating/#repeat-step]
{noformat}
g.V(1).repeat(out()).times(2).emit().path().by('name')
{noformat}
"The first time (*1st*) through the repeat(), the vertices lop, vadas, and josh
are seen. Given that loops==0, the traverser repeats (*2nd*). However, because
the emit-predicate is declared true, those vertices are emitted. At step 2
(loops==1), the vertices traversed are ripple and lop (Josh’s created projects,
as lop and vadas have no out edges) and are also emitted. Now loops==1 so the
traverser repeats. (*3rd*) As ripple and lop have no out edges there are no
vertices to traverse. Given that loops==2, the until-predicate fails."
This clearly indicates that the traverser repeats *3 times* for a *times(2)*,
consistent with do while semantics.
The emit clause does not affect any of this this, so lets drop it. New example,
{noformat}
@Test
public void testTimesAfterRepeat() {
final TinkerGraph g = TinkerGraph.open();
Vertex a1 = g.addVertex(T.label, "A", "name", "a1");
Vertex b1 = g.addVertex(T.label, "B", "name", "b1");
Vertex c1 = g.addVertex(T.label, "C", "name", "c1");
a1.addEdge("ab", b1);
b1.addEdge("bc", c1);
List<Vertex> vertices =
g.traversal().V(a1).repeat(__.out()).times(1).toList();
assertEquals(1, vertices.size());
assertEquals(c1, vertices.get(0));
}
{noformat}
do while should return c1. It does not instead b1 is return because it only
repeats once.
> times(x) after RepeatStep violates do while semantics.
> ------------------------------------------------------
>
> Key: TINKERPOP3-949
> URL: https://issues.apache.org/jira/browse/TINKERPOP3-949
> Project: TinkerPop 3
> Issue Type: Bug
> Components: process
> Affects Versions: 3.0.2-incubating
> Reporter: pieter martin
> Assignee: Daniel Kuppitz
>
> {noformat}
> @Test
> public void testTimesAfterRepeat() {
> final TinkerGraph g = TinkerGraph.open();
> Vertex a1 = g.addVertex(T.label, "A", "name", "a1");
> Vertex b1 = g.addVertex(T.label, "B", "name", "b1");
> Vertex c1 = g.addVertex(T.label, "C", "name", "c1");
> Vertex d1 = g.addVertex(T.label, "D", "name", "d1");
> a1.addEdge("ab", b1);
> b1.addEdge("bc", c1);
> c1.addEdge("cd", d1);
> List<Vertex> vertices =
> g.traversal().V().hasLabel("A").emit().repeat(__.out()).times(2).toList();
> assertEquals(4, vertices.size());
> }
> {noformat}
> This test will fail for as it will return only 3 vertices.
> The current implementation of RepeatStep implements {{while do}} semantics
> for a {{LoopTraversal}} regardless of the position of the {{times}} clause in
> the gremlin query.
> a1->b1->c1->d1
> start at a1, emit a1
> travers to b1 loop==0
> emit b1 travers c1 loop==1
> emit c1 traverse d1 loop==2
> d1 is the last element so it is returned.
> a1, b1, c1 emitted and d1 is the last.
> Ultimately if I understand the intended semantics correctly,
> {{repeat().times(a)}} is equivalent to {{times(a + 1).repeat()}}
> Having a look at {{RepeatStep.standardAlgorithm}} I see that the loop counter
> is always incremented before {{doUntil}}. This translates to {{while do}}
> semantics. For {{do while}} semantics the increment should occur after the
> {{doUntil}}
> Or the {{LoopTraversal}} should be smarter about its predicate for {{do
> while}}
> I am testing on the 3.0.2-incubating branch. I have only been working on
> repeatSteps that start from a GraphStep. The same applies to starting from a
> VertexStep but I am not yet there.
> With my current understanding of {{LoopTraversal}} and {{do while}} semantics
> the following tests are failling,
> {{RepeatTest.g_V_repeatXoutX_timesX2X}}
> {{RepeatTest.g_V_repeatXoutX_timesX2X_repeatXinX_timesX2X_name}}
> {{PathTest.g_V_repeatXoutX_timesX2X_path_byXitX_byXnameX_byXlangX}}
> {{GroupTest.g_V_repeatXbothXfollowedByXX_timesX2X_group_byXsongTypeX_byXcountX}}
> {{GroupTest.g_V_repeatXbothXfollowedByXX_timesX2X_groupXaX_byXsongTypeX_byXcountX_capXaX}}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)