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

    https://github.com/apache/spark/pull/20980#discussion_r183374541
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
 ---
    @@ -1255,8 +1255,64 @@ case class ExternalMapToCatalyst private(
       override def dataType: MapType = MapType(
         keyConverter.dataType, valueConverter.dataType, valueContainsNull = 
valueConverter.nullable)
     
    -  override def eval(input: InternalRow): Any =
    -    throw new UnsupportedOperationException("Only code-generated 
evaluation is supported")
    +  private lazy val mapCatalystConverter: Any => (Array[Any], Array[Any]) = 
child.dataType match {
    +    case ObjectType(cls) if classOf[java.util.Map[_, 
_]].isAssignableFrom(cls) =>
    +      (input: Any) => {
    +        val data = input.asInstanceOf[java.util.Map[Any, Any]]
    +        val keys = new Array[Any](data.size)
    +        val values = new Array[Any](data.size)
    +        val iter = data.entrySet().iterator()
    +        var i = 0
    +        while (iter.hasNext) {
    +          val entry = iter.next()
    +          val (key, value) = (entry.getKey, entry.getValue)
    +          keys(i) = if (key != null) {
    +            keyConverter.eval(InternalRow.fromSeq(key :: Nil))
    --- End diff --
    
    Please reuse the `InternalRow`.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to