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

ASF GitHub Bot commented on TINKERPOP-1211:
-------------------------------------------

Github user twilmes commented on a diff in the pull request:

    https://github.com/apache/tinkerpop/pull/475#discussion_r86026558
  
    --- Diff: 
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/UnfoldStep.java
 ---
    @@ -46,6 +47,8 @@ else if (s instanceof Iterable)
                 return ((Iterable) s).iterator();
             else if (s instanceof Map)
                 return ((Map) s).entrySet().iterator();
    +        else if (s.getClass().isArray())
    +            return new ArrayIterator((Object[])s);
    --- End diff --
    
    This cast will fail if the incoming array is an array of primitives.  I 
think you could do something like this which is short and to the point but 
creates an intermediate, albeit short-lived list.
    `return (Iterator<E>)Arrays.asList(s).iterator();`
    
    I was able to reproduce the issue when I nested a primitive array inside of 
a list.  Calling `unfold` twice looks a little silly but maybe someone would do 
this if they were dealing with nested collections.
    
    ```
    gremlin> __.inject([0, 1, 2, [3, 4] as int[]]).unfold().unfold()
    ==>0
    ==>1
    ==>2
    [I cannot be cast to [Ljava.lang.Object;
    Type ':help' or ':h' for help.
    Display stack trace? [yN]n
    gremlin> __.inject([0, 1, 2, [3, 4]]).unfold().unfold()
    ==>0
    ==>1
    ==>2
    ==>3
    ==>4
    ```


> UnfoldStep should unfold arrays.
> --------------------------------
>
>                 Key: TINKERPOP-1211
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-1211
>             Project: TinkerPop
>          Issue Type: Bug
>          Components: process
>    Affects Versions: 3.1.1-incubating
>            Reporter: Marko A. Rodriguez
>              Labels: breaking
>
> Currently {{UnfoldStep}} does not unfold arrays as an array does not 
> implement {{Iterable}} or {{Iterator}}. We simply need to check if the 
> current object is an array, and if so, set the flatMap-iterator to 
> {{ArrayIterator}}.
> This would be breaking, but I doubt anyone ever uses arrays or would find 
> this a problem. I'm sure anyone who wanted to {{unfold}} an array was like: 
> "whaaaaa?"



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to