[
https://issues.apache.org/jira/browse/TINKERPOP-2209?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16834103#comment-16834103
]
Daniel Kuppitz commented on TINKERPOP-2209:
-------------------------------------------
This is the expected behavior. {{hasId}} accepts varargs; a collection is a
single argument, thus it will be translated into {{eq()}}. However, if you pass
an array, it will be translated into {{within}}.
{code:java}
gremlin> ids = [8440,12536]
==>8440
==>12536
gremlin>
g.V(ids).until(hasId(ids)).repeat(out().simplePath()).limit(10).path().toString()[0..<100]
==>[GraphStep(vertex,[8440, 12536]), RepeatStep(until([HasStep([~id.eq([8440,
12536])])]),[VertexStep(O
gremlin> ids = [8440,12536].toArray()
==>8440
==>12536
gremlin>
g.V(ids).until(hasId(ids)).repeat(out().simplePath()).limit(10).path().toString()[0..<100]
==>[GraphStep(vertex,[8440, 12536]),
RepeatStep(until([HasStep([~id.within([8440, 12536])])]),[VertexSt
{code}
{{g.V(ids)}} returns all vertices, because {{GraphStep}} is the only step that
unfolds collections internally. {{g.V().hasId(ids)}} returns all vertices,
because in this case, {{hasId}} gets folded into {{GraphStep}}. Theoretically,
we could remove the automatic unfolding in {{GraphStep}}, but practically, this
would be a major breaking change. Likewise, we can't do the automatic unfolding
for every other step, as you wouldn't be able to actually test for equal
collections anymore.
> hasId is not converting properly when multiple values are passed
> ----------------------------------------------------------------
>
> Key: TINKERPOP-2209
> URL: https://issues.apache.org/jira/browse/TINKERPOP-2209
> Project: TinkerPop
> Issue Type: Bug
> Components: process
> Affects Versions: 3.3.3
> Environment: loaded GraphOfTheGods in JanusGraph 0.3.1 on a macbook.
> Reporter: Chris Hupman
> Priority: Minor
>
> While [trying to answer a question on Stack Overflow
> |[https://stackoverflow.com/questions/55912624/get-all-edges-between-multiple-vertices-janusgraph/55929179#55929179]]
> I found that hasId is performing `~id.eq` against arrays instead of
> `~id.within` For a workaround the user reporting the issue found that quoting
> the values or converting them to longs worked.
>
> ```
> {{ids = [8440,12536]}}
> {{paths =
> g.V(ids).until(hasId(ids)).repeat(out().simplePath()).limit(10).path().explain()}}
> {{...RepeatStep(until([HasStep([~id.eq([4112, 4128, ...])])]),}}{{}}
> {{paths =
> g.V(ids).until(hasId("8440","12536")).repeat(outE().simplePath()).limit(10).path().explain()}}
> {{...RepeatStep(until([HasStep([~id.within([8440, 12536])])])}}
> ```
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)