[ 
https://issues.apache.org/jira/browse/TINKERPOP-2869?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17690438#comment-17690438
 ] 

Stephen Mallette commented on TINKERPOP-2869:
---------------------------------------------

> May I know if it is correct to filter the node x in this way:

I'm not sure what you mean by "correct". Everything you've shown is valid 
syntax. I think you're just misunderstanding the expected behavior.

>  I would expect them to output the same results.

The output will not be the same for essentially the same reasons I've mentioned 
before. Maybe the following will help you see the difference (and hopefully 
won't confuse you more):

{code}
gremlin> 
g.V().as('x').hasLabel('A').bothE().dedup().otherV().select('x').count()
==>36
gremlin> 
g.V().as('x').bothE().dedup().otherV().select('x').hasLabel('A').count()
==>31
{code}

So the above are your two traversals and results. Now watch what happens when 
we change the order of the the starting vertices for the first query:

{code}
gremlin> 
g.V().order().by(shuffle).as('x').hasLabel('A').bothE().dedup().otherV().select('x').count()
==>36
gremlin> 
g.V().order().by(shuffle).as('x').hasLabel('A').bothE().dedup().otherV().select('x').count()
==>36
gremlin> 
g.V().order().by(shuffle).as('x').hasLabel('A').bothE().dedup().otherV().select('x').count()
==>36
{code} 

Nothing changes because no matter what we do we start with "A" vertices and 
dedup their edges, which means the {{otherV()}} must always be "B" vertices. 
Now watch what happens if we introduce the same {{shuffle}} to your second 
query:

{code}
gremlin> 
g.V().order().by(shuffle).as('x').bothE().dedup().otherV().select('x').hasLabel('A').count()
==>26
gremlin> 
g.V().order().by(shuffle).as('x').bothE().dedup().otherV().select('x').hasLabel('A').count()
==>24
gremlin> 
g.V().order().by(shuffle).as('x').bothE().dedup().otherV().select('x').hasLabel('A').count()
==>32
gremlin> 
g.V().order().by(shuffle).as('x').bothE().dedup().otherV().select('x').hasLabel('A').count()
==>22
{code}

Maybe also look at your revised query:

{code}
gremlin> 
g.V().as('x').bothE().dedup().otherV().where(__.as('x').hasLabel('A')).count()
==>31
gremlin> 
g.V().order().by(shuffle).as('x').bothE().dedup().otherV().where(__.as('x').hasLabel('A')).count()
==>20
gremlin> 
g.V().order().by(shuffle).as('x').bothE().dedup().otherV().where(__.as('x').hasLabel('A')).count()
==>22
gremlin> 
g.V().order().by(shuffle).as('x').bothE().dedup().otherV().where(__.as('x').hasLabel('A')).count()
==>32
gremlin> 
g.V().order().by(shuffle).as('x').bothE().dedup().otherV().where(__.as('x').hasLabel('A')).count()
==>21
{code}

Different every time. Why? because now you start with "A" or "B" vertices and 
{{otherV()}} may produce either an "A" or "B" vertex. {{dedup()}} is not always 
choosing an A->B direction to traverse but sometimes a B<-A direction to 
traverse so you end up with something different no matter how you choose to 
filter the remainder of the traversal. 

It's perhaps a bit hard to think about (i'm having a hard time coming up with 
the words to explain it). I again suggest that you find a smaller and less 
complicated dataset to try to experiment with what's happening here if this 
still doesn't make sense to you.  I hope this helps.

> Inconsistent results when using dedup()
> ---------------------------------------
>
>                 Key: TINKERPOP-2869
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2869
>             Project: TinkerPop
>          Issue Type: Bug
>    Affects Versions: 3.6.1
>            Reporter: Yuancheng
>            Priority: Major
>
>  
> {code:java}
> g.V().as('x').hasLabel('A').bothE().dedup().otherV().select('x').count()
> result: 36{code}
> {code:java}
> g.V().as('x').bothE().dedup().otherV().select('x').hasLabel('A').count()
> result: 31  {code}
> Dataset: same to https://issues.apache.org/jira/browse/TINKERPOP-2867
> Path results:
> {code:java}
> path[v[0], e[58][0-X->15], v[15], v[0]]
> path[v[0], e[60][0-X->12], v[12], v[0]]
> path[v[0], e[30][0-X->3], v[3], v[0]]
> path[v[0], e[49][0-Y->27], v[27], v[0]]
> path[v[0], e[52][0-Y->21], v[21], v[0]]
> path[v[0], e[78][0-Y->24], v[24], v[0]]
> path[v[0], e[39][27-X->0], v[27], v[0]]
> path[v[0], e[61][3-X->0], v[3], v[0]]
> path[v[0], e[70][3-Y->0], v[3], v[0]]
> path[v[0], e[40][3-Y->0], v[3], v[0]]
> path[v[0], e[59][3-Y->0], v[3], v[0]]
> path[v[3], e[53][3-X->21], v[21], v[3]]
> path[v[3], e[31][3-X->6], v[6], v[3]]
> path[v[3], e[74][3-Y->12], v[12], v[3]]
> path[v[3], e[67][21-X->3], v[21], v[3]]
> path[v[3], e[71][21-Y->3], v[21], v[3]]
> path[v[3], e[56][24-Y->3], v[24], v[3]]
> path[v[3], e[41][6-Y->3], v[6], v[3]]
> path[v[6], e[32][6-X->9], v[9], v[6]]
> path[v[6], e[50][6-X->24], v[24], v[6]]
> path[v[6], e[62][6-X->12], v[12], v[6]]
> path[v[6], e[77][6-Y->21], v[21], v[6]] (MISSED)
> path[v[6], e[69][27-X->6], v[27], v[6]]
> path[v[6], e[55][18-X->6], v[18], v[6]] (MISSED)
> path[v[6], e[51][15-Y->6], v[15], v[6]]
> path[v[6], e[72][24-Y->6], v[24], v[6]]
> path[v[6], e[42][9-Y->6], v[9], v[6]]
> path[v[9], e[33][9-X->12], v[12], v[9]]
> path[v[9], e[63][9-X->18], v[18], v[9]] (MISSED)
> path[v[9], e[73][24-Y->9], v[24], v[9]] (MISSED)
> path[v[9], e[43][12-Y->9], v[12], v[9]]
> path[v[12], e[64][12-X->15], v[15], v[12]]
> path[v[12], e[34][12-X->15], v[15], v[12]]
> path[v[12], e[54][12-Y->21], v[21], v[12]] (MISSED)
> path[v[12], e[65][15-X->12], v[15], v[12]]
> path[v[12], e[44][15-Y->12], v[15], v[12]] {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to