Skip to content

Commit f6eb35a

Browse files
committed
[SPARK-12599][MLlib][SQL] Remove the use of the deprecated callUDF in MLlib.
1 parent 0da7bd5 commit f6eb35a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

mllib/src/main/scala/org/apache/spark/ml/Transformer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ abstract class UnaryTransformer[IN, OUT, T <: UnaryTransformer[IN, OUT, T]]
115115

116116
override def transform(dataset: DataFrame): DataFrame = {
117117
transformSchema(dataset.schema, logging = true)
118-
dataset.withColumn($(outputCol),
119-
callUDF(this.createTransformFunc, outputDataType, dataset($(inputCol))))
118+
val transformUDF = udf(this.createTransformFunc, outputDataType)
119+
dataset.withColumn($(outputCol), transformUDF(dataset($(inputCol))))
120120
}
121121

122122
override def copy(extra: ParamMap): T = defaultCopy(extra)

sql/core/src/main/scala/org/apache/spark/sql/functions.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,6 +2843,20 @@ object functions extends LegacyFunctions {
28432843
// scalastyle:on parameter.number
28442844
// scalastyle:on line.size.limit
28452845

2846+
/**
2847+
* Defines a user-defined function (UDF) using a Scala closure. For this variant, the caller must
2848+
* specifcy the output data type, and there is no automatic input type coercion.
2849+
*
2850+
* @param f A closure in Scala
2851+
* @param dataType The output data type of the UDF
2852+
*
2853+
* @group udf_funcs
2854+
* @since 2.0.0
2855+
*/
2856+
def udf(f: AnyRef, dataType: DataType): UserDefinedFunction = {
2857+
UserDefinedFunction(f, dataType, None)
2858+
}
2859+
28462860
/**
28472861
* Call an user-defined function.
28482862
* Example:

0 commit comments

Comments
 (0)