cloud-fan commented on a change in pull request #26712: [SPARK-29883][SQL] 
Improve error messages when function name is an alias
URL: https://github.com/apache/spark/pull/26712#discussion_r353039726
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala
 ##########
 @@ -600,7 +600,8 @@ object FunctionRegistry {
       } else {
         // Otherwise, find a constructor method that matches the number of 
arguments, and use that.
         val params = Seq.fill(expressions.size)(classOf[Expression])
-        val f = constructors.find(_.getParameterTypes.toSeq == 
params).getOrElse {
+        val f = constructors.find(e => e.getParameterTypes.toSeq == params
+            || e.getParameterTypes.head == classOf[String]).getOrElse {
 
 Review comment:
   Seems like it's less hacky to create a new `expressionWithAlias` method, 
with only the necessary logic
   ```
   def expressionWithAlias ... = {
     val constructors = tag.runtimeClass.getConstructors
       .filter(c => e.getParameterTypes.head == classOf[String])
     assert(constructors.length == 1)
     try {
       constructors.head.newInstance(name, expressions : 
_*).asInstanceOf[Expression]
     } ...
   }
   ```

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to