Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-2730

When retrieving a value from a Map, GetItem evaluates key twice

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 1.0.3, 1.1.0
    • SQL
    • None

    Description

      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
              }
            }
          }
        }
      

      Attachments

        Activity

          People

            yhuai Yin Huai
            yhuai Yin Huai
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: