maropu commented on a change in pull request #24014: [SPARK-27092][SQL] Apply
refactored pattern in ScalaReflection and JavaTypeInference to RowEncoder
URL: https://github.com/apache/spark/pull/24014#discussion_r264091667
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/encoders/RowEncoder.scala
##########
@@ -87,142 +89,50 @@ object RowEncoder {
"SQLUserDefinedType nor registered with UDTRegistration.}")
}
}
- val obj = NewInstance(
- udtClass,
- Nil,
- dataType = ObjectType(udtClass), false)
- Invoke(obj, "serialize", udt, inputObject :: Nil, returnNullable = false)
+ createSerializerForUserDefinedType(inputObject, udt, udtClass,
propagateNull = false,
+ returnNullable = false)
case TimestampType if SQLConf.get.datetimeJava8ApiEnabled =>
- StaticInvoke(
- DateTimeUtils.getClass,
- TimestampType,
- "instantToMicros",
- inputObject :: Nil,
- returnNullable = false)
+ createSerializerForJavaInstant(inputObject)
- case TimestampType =>
- StaticInvoke(
- DateTimeUtils.getClass,
- TimestampType,
- "fromJavaTimestamp",
- inputObject :: Nil,
- returnNullable = false)
+ case TimestampType => createSerializerForSqlTimestamp(inputObject)
case DateType if SQLConf.get.datetimeJava8ApiEnabled =>
- StaticInvoke(
- DateTimeUtils.getClass,
- DateType,
- "localDateToDays",
- inputObject :: Nil,
- returnNullable = false)
+ createSerializerForJavaLocalDate(inputObject)
- case DateType =>
- StaticInvoke(
- DateTimeUtils.getClass,
- DateType,
- "fromJavaDate",
- inputObject :: Nil,
- returnNullable = false)
+ case DateType => createSerializerForSqlDate(inputObject)
- case d: DecimalType =>
- CheckOverflow(StaticInvoke(
- Decimal.getClass,
- d,
- "fromDecimal",
- inputObject :: Nil,
- returnNullable = false), d)
-
- case StringType =>
- StaticInvoke(
- classOf[UTF8String],
- StringType,
- "fromString",
- inputObject :: Nil,
- returnNullable = false)
+ case d: DecimalType => createSerializerForDecimalType(inputObject, d)
+
+ case StringType => createSerializerForString(inputObject)
case t @ ArrayType(et, containsNull) =>
et match {
case BooleanType | ByteType | ShortType | IntegerType | LongType |
FloatType | DoubleType =>
- StaticInvoke(
- classOf[ArrayData],
- t,
- "toArrayData",
- inputObject :: Nil,
- returnNullable = false)
-
- case _ => MapObjects(
+ createSerializerForPrimitiveArrayViaArrayData(inputObject, t)
+
+ case _ => createSerializerForMapObjects(inputObject,
ObjectType(classOf[Object]),
Review comment:
nit: style
```
case _ =>
createSerializerForMapObjects(
inputObject,
ObjectType(classOf[Object]),
element => {
val value = serializerFor(ValidateExternalType(element, et),
et)
expressionWithNullSafety(value, containsNull, WalkedTypePath())
})
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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]