You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by "Stephen Mallette (Jira)" <ji...@apache.org> on 2021/01/26 13:08:00 UTC

[jira] [Commented] (TINKERPOP-2510) by-modulator throws when token is used after elementMap()

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

Stephen Mallette commented on TINKERPOP-2510:
---------------------------------------------

This is an unfortunate inconsistency made the worse as there is no direct workaround. Your only recourse is to {{group()}} and then {{elementMap()}} which is the same output:

{code}
gremlin> g.V().group().by(id).by(elementMap()).next()
==>1={id=1, label=person, name=marko, age=29}
==>2={id=2, label=person, name=vadas, age=27}
==>3={id=3, label=software, name=lop, lang=java}
==>4={id=4, label=person, name=josh, age=32}
==>5={id=5, label=software, name=ripple, lang=java}
==>6={id=6, label=person, name=peter, age=35}
{code}

i would like to see all {{Map}} operations behave like {{Element}} operations so that we don't have these sorts of problems. Some efforts have been made in this area but we still have problems like this one you've run into. i'm not even sure it can be fixed without a breaking change, so it likely will have to come in as part of 3.5.0 or later.

> by-modulator throws when token is used after elementMap()
> ---------------------------------------------------------
>
>                 Key: TINKERPOP-2510
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2510
>             Project: TinkerPop
>          Issue Type: Bug
>    Affects Versions: 3.4.9
>            Reporter: Christopher Smith
>            Priority: Major
>
> I'm attempting to write a "join" traversal to return the values of several related vertices (of different types), starting from an entry vertex. In order to extract the relevant properties, I am currently using {{elementMap}}, then trying to stash the vertex properties to continue with my query:
> {code:groovy}
> gts.V(entryPoint).as('p')
>   .sideEffect(__.elementMap().group('pp').by(T.id))
>   .out...
>   ...
>   .select('pp', ...)
> {code}
> As {{elementMap}} produces a map that includes the tokens as map keys, I expected {{by(T.id)}} to extract a map keyed on the vertex ID with the properties as the value (right now folded, but I'm crunching on that later). Using strings like {{'firstName'}} works as expected, but of course using the string {{'id'}} does not because the map key is the token, not the string.
> However, passing {{T.id}} to the by-modulator when the value is a map (instead of an element) produces a {{ClassCastException}}. As far as I can tell, the processor is assuming somewhere that {{by(T.id)}} indicates that the incoming value is an element, which (at least after the addition of {{elementMap}}) is not true.
> {code}
> java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class org.apache.tinkerpop.gremlin.structure.Element (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; org.apache.tinkerpop.gremlin.structure.Element is in unnamed module of loader 'app')
> 	at org.apache.tinkerpop.gremlin.process.traversal.lambda.TokenTraversal.addStart(TokenTraversal.java:46)
> 	at org.apache.tinkerpop.gremlin.process.traversal.util.TraversalUtil.apply(TraversalUtil.java:42)
> 	at org.apache.tinkerpop.gremlin.process.traversal.util.TraversalUtil.applyNullable(TraversalUtil.java:87)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.GroupSideEffectStep.sideEffect(GroupSideEffectStep.java:114)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SideEffectStep.processNextStart(SideEffectStep.java:39)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143)
> 	at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.hasNext(DefaultTraversal.java:197)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.TraversalSideEffectStep.sideEffect(TraversalSideEffectStep.java:48)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SideEffectStep.processNextStart(SideEffectStep.java:39)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:50)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.map.FlatMapStep.processNextStart(FlatMapStep.java:48)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:50)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep.processNextStart(FilterStep.java:37)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:50)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.map.FlatMapStep.processNextStart(FlatMapStep.java:48)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:50)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.map.FlatMapStep.processNextStart(FlatMapStep.java:48)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:50)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep.processNextStart(FilterStep.java:37)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:50)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.map.FlatMapStep.processNextStart(FlatMapStep.java:48)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:50)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.map.MapStep.processNextStart(MapStep.java:36)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.map.SelectOneStep.processNextStart(SelectOneStep.java:131)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.next(AbstractStep.java:128)
> 	at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.next(AbstractStep.java:38)
> 	at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.next(DefaultTraversal.java:205)
> 	at com.example.Queries.query(Queries.groovy:39)
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)