HeartSaVioR commented on a change in pull request #23854: [SPARK-22000][SQL] 
Address missing Upcast in JavaTypeInference.deserializerFor
URL: https://github.com/apache/spark/pull/23854#discussion_r260277442
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/JavaTypeInference.scala
 ##########
 @@ -212,82 +219,99 @@ object JavaTypeInference {
                 c == classOf[java.lang.Float] ||
                 c == classOf[java.lang.Byte] ||
                 c == classOf[java.lang.Boolean] =>
-        StaticInvoke(
-          c,
-          ObjectType(c),
-          "valueOf",
-          path :: Nil,
-          returnNullable = false)
+        createDeserializerForTypesSupportValueOf(path, c)
 
       case c if c == classOf[java.sql.Date] =>
-        StaticInvoke(
-          DateTimeUtils.getClass,
-          ObjectType(c),
-          "toJavaDate",
-          path :: Nil,
-          returnNullable = false)
+        createDeserializerForSqlDate(path)
 
       case c if c == classOf[java.sql.Timestamp] =>
-        StaticInvoke(
-          DateTimeUtils.getClass,
-          ObjectType(c),
-          "toJavaTimestamp",
-          path :: Nil,
-          returnNullable = false)
+        createDeserializerForSqlTimestamp(path)
 
       case c if c == classOf[java.lang.String] =>
-        Invoke(path, "toString", ObjectType(classOf[String]))
+        createDeserializerForString(path, returnNullable = true)
 
       case c if c == classOf[java.math.BigDecimal] =>
-        Invoke(path, "toJavaBigDecimal", 
ObjectType(classOf[java.math.BigDecimal]))
+        createDeserializerForJavaBigDecimal(path, returnNullable = true)
+
+      case c if c == classOf[java.math.BigInteger] =>
+        createDeserializerForJavaBigInteger(path, returnNullable = true)
 
       case c if c.isArray =>
         val elementType = c.getComponentType
-        val primitiveMethod = elementType match {
-          case c if c == java.lang.Boolean.TYPE => Some("toBooleanArray")
-          case c if c == java.lang.Byte.TYPE => Some("toByteArray")
-          case c if c == java.lang.Short.TYPE => Some("toShortArray")
-          case c if c == java.lang.Integer.TYPE => Some("toIntArray")
-          case c if c == java.lang.Long.TYPE => Some("toLongArray")
-          case c if c == java.lang.Float.TYPE => Some("toFloatArray")
-          case c if c == java.lang.Double.TYPE => Some("toDoubleArray")
-          case _ => None
-        }
-
-        primitiveMethod.map { method =>
-          Invoke(path, method, ObjectType(c))
-        }.getOrElse {
-          Invoke(
-            MapObjects(
-              p => deserializerFor(typeToken.getComponentType, p),
-              path,
-              inferDataType(elementType)._1),
-            "array",
-            ObjectType(c))
+        val newTypePath = s"""- array element class: 
"${elementType.getCanonicalName}"""" +:
+          walkedTypePath
+        val (dataType, elementNullable) = inferDataType(elementType)
+
+        if (elementNullable) {
+          val mapFunction: Expression => Expression = element => {
+            // upcast the array element to the data type the encoder expected.
+            deserializerForWithNullSafetyAndUpcast(
+              element,
+              dataType,
+              nullable = elementNullable,
+              newTypePath,
+              (casted, typePath) => 
deserializerFor(typeToken.getComponentType, casted, typePath))
+          }
+          val arrayData = MapObjects(mapFunction, path, dataType)
+          Invoke(arrayData, "array", ObjectType(c), returnNullable = false)
+        } else {
+          val primitiveMethod = elementType match {
+            case c if c == java.lang.Integer.TYPE => Some("toIntArray")
+            case c if c == java.lang.Long.TYPE => Some("toLongArray")
+            case c if c == java.lang.Double.TYPE => Some("toDoubleArray")
+            case c if c == java.lang.Float.TYPE => Some("toFloatArray")
+            case c if c == java.lang.Short.TYPE => Some("toShortArray")
+            case c if c == java.lang.Byte.TYPE => Some("toByteArray")
+            case c if c == java.lang.Boolean.TYPE => Some("toBooleanArray")
+            case _ => None
+          }
+          primitiveMethod.map { method =>
+            Invoke(path, method, ObjectType(c))
+          }.getOrElse {
+            Invoke(
 
 Review comment:
   Hmm... sorry I think I was a bit confused. After looking into it again, the 
content before this commit seems correct and also in sync with ScalaReflection. 
I'll revert it back.
   Btw, the difference between previous code is that new code handles upcast 
which ScalaReflection also handles it.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to