cloud-fan commented on a change in pull request #28645:
URL: https://github.com/apache/spark/pull/28645#discussion_r433673986
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -2847,6 +2848,39 @@ class Analyzer(
}
}
+ object PrepareDeserializerForUDF extends Rule[LogicalPlan] {
+ override def apply(plan: LogicalPlan): LogicalPlan =
plan.resolveOperatorsUp {
+ case p if !p.resolved => p // Skip unresolved nodes.
+
+ case p => p transformExpressionsUp {
+
+ case udf @ ScalaUDF(_, _, inputs, encoders, _, _, _, desers)
+ if encoders.nonEmpty && desers.isEmpty =>
+ val deserializers = encoders.zipWithIndex.map { case (encOpt, i) =>
+ val dataType = inputs(i).dataType
+ if (CatalystTypeConverters.isPrimitive(dataType) ||
+ dataType.isInstanceOf[UserDefinedType[_]]) {
+ // primitive/UDT data types use `CatalystTypeConverters` to
+ // convert internal data to external data.
+ None
+ } else {
+ encOpt.map { enc =>
+ val attrs = if (enc.isSerializedAsStructForTopLevel) {
+ dataType.asInstanceOf[StructType].toAttributes
+ } else {
+ // the field name doesn't matter here, so we use
+ // a simple literal to avoid any overhead
+ new StructType().add(s"input", dataType).toAttributes
+ }
+ enc.resolveAndBind(attrs).createDeserializer()
Review comment:
We can't bind the attributes during analysis.
----------------------------------------------------------------
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]