[
https://issues.apache.org/jira/browse/TINKERPOP3-949?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15002532#comment-15002532
]
pieter martin commented on TINKERPOP3-949:
------------------------------------------
In the given example c1 is the last emit() element but the traversal still
happens.
d1 is the last/leaf element and I expected it to be returned.
The following gremlin is what informed my understanding of last/leaf elements
and emittings.
{noformat}
final TinkerGraph graph = TinkerGraph.open();
Vertex a1 = graph.addVertex(T.label, "A", "name", "a1");
Vertex b1 = graph.addVertex(T.label, "B", "name", "b1");
Vertex c1 = graph.addVertex(T.label, "C", "name", "c1");
Vertex d1 = graph.addVertex(T.label, "D", "name", "d1");
a1.addEdge("ab", b1);
b1.addEdge("bc", c1);
c1.addEdge("cd", d1);
List<Path> paths =
graph.traversal().V(a1).times(3).repeat(__.out()).emit().path().toList();
for (Path path : paths) {
System.out.println(path);
}
{noformat}
This will output
{noformat}
[v[0], v[2]]
[v[0], v[2], v[4]]
[v[0], v[2], v[4], v[6]]
[v[0], v[2], v[4], v[6]]
{noformat}
v6 is repeated.
In this case v6 is emitted as per usual, it is also the last/leaf element and
returned as per usual.
So emits always emit and leaf elements is always returned.
In the original example d1 is the leaf element but yet is not returned.
> 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)