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

    https://github.com/apache/spark/pull/13909#discussion_r88165267
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeCreator.scala
 ---
    @@ -133,50 +153,79 @@ case class CreateMap(children: Seq[Expression]) 
extends Expression {
         new ArrayBasedMapData(new GenericArrayData(keyArray), new 
GenericArrayData(valueArray))
       }
     
    +  private def getAccessors(ctx: CodegenContext, dt: DataType, array: 
String,
    +      isPrimitive : Boolean, size: Int): (String, String, String) = {
    +    if (!isPrimitive) {
    +      val arrayClass = classOf[GenericArrayData].getName
    +      ctx.addMutableState("Object[]", array, s"this.$array = null;")
    +      (s"new $arrayClass($array)",
    +        s"$array = new Object[${size}];", s"this.$array = null;")
    +    } else {
    +      val unsafeArrayClass = classOf[UnsafeArrayData].getName
    +      val javaDataType = ctx.javaType(dt)
    +      ctx.addMutableState(s"${javaDataType}[]", array,
    +        s"this.$array = new ${javaDataType}[${size}];")
    +      (s"$unsafeArrayClass.fromPrimitiveArray($array)", "", "")
    +    }
    +  }
    +
       override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
    -    val arrayClass = classOf[GenericArrayData].getName
         val mapClass = classOf[ArrayBasedMapData].getName
         val keyArray = ctx.freshName("keyArray")
         val valueArray = ctx.freshName("valueArray")
    -    ctx.addMutableState("Object[]", keyArray, s"this.$keyArray = null;")
    -    ctx.addMutableState("Object[]", valueArray, s"this.$valueArray = 
null;")
     
    -    val keyData = s"new $arrayClass($keyArray)"
    -    val valueData = s"new $arrayClass($valueArray)"
    +    val MapType(keyDt, valueDt, _) = dataType
    +    val evalKeys = keys.map(e => e.genCode(ctx))
    +    val isPrimitiveArrayKey = ctx.isPrimitiveType(keyDt)
    +    val isNonNullKey = evalKeys.forall(_.isNull == "false")
    --- End diff --
    
    Also we should use `keys.forall(!_.nullable)` here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to