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_r260279960
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/JavaTypeInference.scala
##########
@@ -212,82 +219,90 @@ 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 => "toIntArray"
+ case c if c == java.lang.Long.TYPE => "toLongArray"
+ case c if c == java.lang.Double.TYPE => "toDoubleArray"
+ case c if c == java.lang.Float.TYPE => "toFloatArray"
+ case c if c == java.lang.Short.TYPE => "toShortArray"
+ case c if c == java.lang.Byte.TYPE => "toByteArray"
+ case c if c == java.lang.Boolean.TYPE => "toBooleanArray"
+ case other => throw new IllegalStateException("expect primitive
array element type " +
Review comment:
@maropu
Sorry to make a confusion. I wasn't wrong so the change was unnecessary, so
I'm rolling back the change. To answer the origin comment, non-nullable &
non-primitive case => not possible according to the implementation of
`inferDataType`. `nullable = true` for only primitive case.
----------------------------------------------------------------
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]