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

    https://github.com/apache/spark/pull/19797#discussion_r152719657
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeCreator.scala
 ---
    @@ -87,35 +87,41 @@ private [sql] object GenArrayData {
           elementType: DataType,
           elementsCode: Seq[ExprCode],
           isMapKey: Boolean): (String, Seq[String], String, String) = {
    -    val arrayName = ctx.freshName("array")
         val arrayDataName = ctx.freshName("arrayData")
         val numElements = elementsCode.length
     
         if (!ctx.isPrimitiveType(elementType)) {
    +      val arrayName = "arrayObject"
           val genericArrayClass = classOf[GenericArrayData].getName
    -      ctx.addMutableState("Object[]", arrayName,
    -        s"$arrayName = new Object[$numElements];")
    +      if (!ctx.mutableStates.exists(s => s._1 == arrayName)) {
    +        ctx.addMutableState("Object[]", arrayName)
    +      }
     
           val assignments = elementsCode.zipWithIndex.map { case (eval, i) =>
    -        val isNullAssignment = if (!isMapKey) {
    -          s"$arrayName[$i] = null;"
    +        val isNullAssignment = if (eval.isNull == "false") {
    +          ""
    --- End diff --
    
    This don't really simplify the code since you still have the `else` block 
below. It complicates the codes here actually. So I think it is better to be 
unchanged.


---

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

Reply via email to