zhengruifeng commented on code in PR #41687:
URL: https://github.com/apache/spark/pull/41687#discussion_r1242871046
##########
sql/core/src/main/scala/org/apache/spark/sql/functions.scala:
##########
@@ -7715,9 +7688,30 @@ object functions {
* @since 3.2.0
*/
@scala.annotation.varargs
- def call_udf(udfName: String, cols: Column*): Column = withExpr {
- UnresolvedFunction(udfName, cols.map(_.expr), isDistinct = false)
- }
+ @deprecated("Use call_function")
+ def call_udf(udfName: String, cols: Column*): Column =
+ call_function(udfName, cols: _*)
+
+ /**
+ * Call a builtin or temp function.
+ *
+ * @param funcName function name
+ * @param cols the expression parameters of function
+ * @since 3.5.0
+ */
+ def call_function(funcName: String, cols: Column*): Column =
+ withExpr { UnresolvedFunction(funcName, cols.map(_.expr), false) }
+
+ /**
+ * Call a builtin or temp function.
+ *
+ * @param funcName function name
+ * @param cols the expression parameters of function
+ * @param isDistinct the distinct for aggregate functions
+ * @since 3.5.0
+ */
+ def call_function(funcName: String, isDistinct: Boolean, cols: Column*):
Column =
Review Comment:
qq:
1, dose parameter `isDistinct` works for all the functions?
2, since `call_function` can invoke both built-in functions and udfs, shall
we add a new parameter `isBuiltIn` or `isUDF` to specify the where to look up
the function? so that we can invoke a built-in function even it is overrided by
udfs, e.g.
```
scala> import org.apache.spark.sql.functions._
import org.apache.spark.sql.functions._
scala> val df = Seq(("a", "A"), ("b", "B")).toDF("key", "value")
df: org.apache.spark.sql.DataFrame = [key: string, value: string]
scala> df.selectExpr("upper(key)").show
+----------+
|upper(key)|
+----------+
| A|
| B|
+----------+
scala> val foo = udf{str: String => str.toUpperCase() + "_X"}
foo: org.apache.spark.sql.expressions.UserDefinedFunction =
SparkUserDefinedFunction($Lambda$3089/0x000000080140f040@6ccb2162,StringType,List(Some(class[value[0]:
string])),Some(class[value[0]: string]),None,true,true)
scala> spark.udf.register("upper", foo.asNondeterministic())
23/06/26 15:15:09 WARN SimpleFunctionRegistry: The function upper replaced a
previously registered function.
res1: org.apache.spark.sql.expressions.UserDefinedFunction =
SparkUserDefinedFunction($Lambda$3089/0x000000080140f040@6ccb2162,StringType,List(Some(class[value[0]:
string])),Some(class[value[0]: string]),Some(upper),true,false)
scala> df.selectExpr("upper(key)").show
+----------+
|upper(key)|
+----------+
| A_X|
| B_X|
+----------+
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]