You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Apache Spark (JIRA)" <ji...@apache.org> on 2014/07/29 19:02:38 UTC

[jira] [Commented] (SPARK-2730) When retrieving a value from a Map, GetItem evaluates key twice

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

Apache Spark commented on SPARK-2730:
-------------------------------------

User 'yhuai' has created a pull request for this issue:
https://github.com/apache/spark/pull/1637

> When retrieving a value from a Map, GetItem evaluates key twice
> ---------------------------------------------------------------
>
>                 Key: SPARK-2730
>                 URL: https://issues.apache.org/jira/browse/SPARK-2730
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>            Reporter: Yin Huai
>            Assignee: Yin Huai
>            Priority: Minor
>
> {code}
> override def eval(input: Row): Any = {
>     val value = child.eval(input)
>     if (value == null) {
>       null
>     } else {
>       val key = ordinal.eval(input)
>       if (key == null) {
>         null
>       } else {
>         if (child.dataType.isInstanceOf[ArrayType]) {
>           // TODO: consider using Array[_] for ArrayType child to avoid
>           // boxing of primitives
>           val baseValue = value.asInstanceOf[Seq[_]]
>           val o = key.asInstanceOf[Int]
>           if (o >= baseValue.size || o < 0) {
>             null
>           } else {
>             baseValue(o)
>           }
>         } else {
>           val baseValue = value.asInstanceOf[Map[Any, _]]
>           val key = ordinal.eval(input) // We evaluate the key again at here
>           baseValue.get(key).orNull
>         }
>       }
>     }
>   }
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)