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



##########
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:
       Ah, I see. Keeping the current behaviour looks good. WDYT? @cloud-fan 
   One question; the fallback is only for the null case?
   




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