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_r264091523
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SerializerBuildHelper.scala
##########
@@ -188,11 +240,45 @@ object SerializerBuildHelper {
expressions.If(IsNull(inputObject), nullOutput, nonNullOutput)
}
+ def createSerializerForExternalRow(
+ inputObject: Expression,
+ fields: Array[StructField],
+ fnSerializerFor: (Expression, DataType) => Expression): Expression = {
+ val nonNullOutput = CreateNamedStruct(fields.zipWithIndex.flatMap { case
(field, index) =>
+ val fieldValue = fnSerializerFor(
+ ValidateExternalType(
+ GetExternalRowField(inputObject, index, field.name),
+ field.dataType),
+ field.dataType)
+ val convertedField = if (field.nullable) {
+ If(
+ Invoke(inputObject, "isNullAt", BooleanType, Literal(index) :: Nil),
+ // Because we strip UDTs, `field.dataType` can be different from
`fieldValue.dataType`.
+ // We should use `fieldValue.dataType` here.
+ Literal.create(null, fieldValue.dataType),
+ fieldValue
+ )
+ } else {
+ fieldValue
+ }
+ Literal(field.name) :: convertedField :: Nil
+ })
+
+ if (inputObject.nullable) {
+ expressionForNullableExpr(inputObject, nonNullOutput)
+ } else {
+ nonNullOutput
+ }
+ }
+
def createSerializerForUserDefinedType(
inputObject: Expression,
udt: UserDefinedType[_],
- udtClass: Class[_]): Expression = {
- val obj = NewInstance(udtClass, Nil, dataType = ObjectType(udtClass))
- Invoke(obj, "serialize", udt, inputObject :: Nil)
+ udtClass: Class[_],
+ propagateNull: Boolean = true,
Review comment:
In `SerializerBuildHelper`/`DeserializerBuildHelper`, some functions have no
argument for `nullable` and, on the other hand, the other functions have an
argument for `nullable`. Is there any consistent policy for the argument here?
----------------------------------------------------------------
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]