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

Stephen Mallette commented on TINKERPOP-2710:
---------------------------------------------

I'm not sure that I can point to one specific discussion about this, but 
{{hasKey()}} is a filter step (which i think accounts for part of the 
difference described in your example) and we have been moving toward 
optimistically filtering rather than throwing exceptions. The biggest example 
of this is with unproductive {{by()}} for 3.6.0:

https://tinkerpop.apache.org/docs/3.6.0-SNAPSHOT/upgrade/#_consistent_by_behavior



> hasKey() should throw an error when invoked on Elements
> -------------------------------------------------------
>
>                 Key: TINKERPOP-2710
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2710
>             Project: TinkerPop
>          Issue Type: Bug
>          Components: language, process
>    Affects Versions: 3.6.0
>            Reporter: Divij Vaidya
>            Priority: Major
>
> *Context*
> hasKey() step can be added to the traversal when the traverser is of type 
> Element or when it is of type Property. 
> When step is invoked for traverser of type property, the behaviour is well 
> defined as, "Remove the {{Property}} traverser if it does not match one of 
> the provided keys." Example query: 
> {noformat}
> gremlin> g.V().properties().hasKey('age').value()
> ==>29
> ==>27
> ==>32
> ==>35{noformat}
> When the step is invoked for traverser of type Element, the behaviour of the 
> step is not documented. [Looking at the 
> code|https://github.com/apache/tinkerpop/blob/master/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/HasContainer.java#L59]
>  implementation, it "removes the element traverser if element has a property 
> with key as '~key' and the value of that property matches 'age'". 
> But [this condition is 
> unsatisfiable|https://github.com/apache/tinkerpop/blob/6a0b71b2af79b1b45f1e2db41946fe85529ed32e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java#L84]
>  because Element can never have a property with key "~key". It would always 
> fail at insertion i.e. the output of hasKey() on Element traverser will 
> always be empty.
> *Change proposed*
> Hence, I propose the following change:
> If hasKey() is applied to a traverser of Element type, then it should throw 
> an error. 
> The code change will be made 
> [here|https://github.com/apache/tinkerpop/blob/master/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/HasContainer.java#L59]
>  . We would introduce a change as follows:
> {noformat}
> if (this.key.equals(T.key.getAccessor())) {
>     throw new IllegalArgumentException("hasKey() cannot be applied to 
> traverser of type Element")
> }{noformat}
> *Impact of the change*
> Before the change:
> {noformat}
> // the following query always returns empty results  gremlin> 
> g.V().hasKey('age').fold() 
> gremlin> g.V().hasKey('age').fold()
> ==>[]{noformat}
>  
> After the change:
> {noformat}
> // the following query returns an error
> gremlin> g.V().hasKey('age').fold()
> hasKey() cannot be applied to traverser of type Element{noformat}
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to