Ngone51 commented on a change in pull request #28979:
URL: https://github.com/apache/spark/pull/28979#discussion_r452188555



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/functions.scala
##########
@@ -4521,9 +4522,10 @@ object functions {
    * @since 1.3.0
    */
   def udf[RT: TypeTag](f: Function0[RT]): UserDefinedFunction = {
-    val ScalaReflection.Schema(dataType, nullable) = 
ScalaReflection.schemaFor[RT]
+    val outputEncoder = Try(ExpressionEncoder[RT]()).toOption
+    val ScalaReflection.Schema(dataType, nullable) = 
outputEncoder.map(_.dataTypeAndNullable).getOrElse(ScalaReflection.schemaFor[RT])

Review comment:
       I compared the support types between `schemaFor` between 
`serializerFor`(which is called by `ExpressionEncoder` indeed). It turns out 
that we can fallback three types: `NullType`, `CalendarInterval`, `Decimal`.
   
   (Actually, I'm thinking why `serializerFor` doesn't support them. )




----------------------------------------------------------------
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]

Reply via email to