[
https://issues.apache.org/jira/browse/TINKERPOP-1973?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16484214#comment-16484214
]
Daniel Kuppitz commented on TINKERPOP-1973:
-------------------------------------------
{quote}the key would be to include the same predicate after the emit{quote}
Right, that's the most common pattern.
{quote}the loop count is no longer available after the traverser has exited the
repeat{quote}
True, but there are several techniques to make it available. The easiest would
be to store the loop counter in the traverser's sack:
{noformat}
g.V()...repeat(...sack(assign).by(loops()))...filter(sack().is(lt(3)))...
{noformat}
If the sack is needed for other things, you can still emit projected values
(containing the actual element and the loop counter).
{noformat}
gremlin>
g.V(1).repeat(optional(select("a")).out().project("a","b").by().by(loops())).emit()
==>[a:v[3],b:0]
==>[a:v[2],b:0]
==>[a:v[4],b:0]
==>[a:v[5],b:1]
==>[a:v[3],b:1]
gremlin>
g.V(1).project("a","b").by().by(constant(-1)).emit().repeat(select("a").out().project("a","b").by().by(loops()))
==>[a:v[1],b:-1]
==>[a:v[3],b:0]
==>[a:v[2],b:0]
==>[a:v[4],b:0]
==>[a:v[5],b:1]
==>[a:v[3],b:1]
{noformat}
> Emit predicate ignored after final loop of a RepeatStep with times or until
> ---------------------------------------------------------------------------
>
> Key: TINKERPOP-1973
> URL: https://issues.apache.org/jira/browse/TINKERPOP-1973
> Project: TinkerPop
> Issue Type: Bug
> Components: process
> Affects Versions: 3.3.3, 3.2.9
> Reporter: Ted Wilmes
> Assignee: Ted Wilmes
> Priority: Major
>
> When combined with a {{times}} or {{until}}, the {{emit}} predicate is not
> applied to the output of the last loop of the {{RepeatStep}}.
> {code}
> gremlin> g = TinkerFactory.createModern().traversal()
> ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
> gremlin> g.V().repeat(out()).emit(has('name', 'lop')).values('name')
> ==>lop
> ==>lop
> ==>lop
> ==>lop
> gremlin> g.V().repeat(out()).times(2).emit(has('name', 'lop')).values('name')
> ==>lop
> ==>ripple
> ==>lop
> ==>lop
> ==>lop
> gremlin>
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)