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

Bob Briody commented on TINKERPOP-1802:
---------------------------------------

The implementation of this seems backwards to me. The `hasId` Step semantics 
are "If an Element Traverser has an ID matching one of the items in this list, 
then emit it, else not.". So when the list is empty, no Element Traversers 
should be emitted, because no Element Traversers have an ID matching an item in 
the list. 

That may seem like a silly thing to do - why specify an empty list that's just 
going to filter out all vertices? Well, if a developer were hard coding an 
empty array then that would be true, but I doubt that is how this will ever 
come up in practice. In practice, I think it will be much more likely for an 
empty array to arrive in a `hasId` step programatically. For example, "Get a 
list of the IDs of Bob's friends. Now use that list in a hasId step in a 
Traversal. ...But suppose Bob doesn't have any friends - that list will be 
empty." This creates situations where things get really ugly, such as this:


{code:java}
def t = g.V(targetId);
t = existingEdgeIds.length == 0 ? t : t.has(id, without(existingEdgeIds));
{code}

...because in order to achieve the natural semantics, one has to modify their 
Traversal depending on dynamic ID lists.

So, I can see why it might seem obvious to assume that an empty list should 
imply that no filtering occurs, and I realize that there are consistency 
concerns wrt g.V()/g.E(), but I still think that the pragmatic usage of this 
step justifies the behavior I described.

> hasId() fails for empty collections
> -----------------------------------
>
>                 Key: TINKERPOP-1802
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-1802
>             Project: TinkerPop
>          Issue Type: Bug
>          Components: process
>    Affects Versions: 3.3.0, 3.2.6
>            Reporter: Daniel Kuppitz
>            Assignee: Marko A. Rodriguez
>
> {noformat}
> gremlin> g.V().hasId(within([]))
> 0
> Type ':help' or ':h' for help.
> Display stack trace? [yN]
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to