Skip to content
Snippets Groups Projects
Commit 513e3b09 authored by Reynold Xin's avatar Reynold Xin
Browse files

[SPARK-12599][MLLIB][SQL] Remove the use of callUDF in MLlib

callUDF has been deprecated. However, we do not have an alternative for users to specify the output data type without type tags. This pull request introduced a new API for that, and replaces the invocation of the deprecated callUDF with that.

Author: Reynold Xin <rxin@databricks.com>

Closes #10547 from rxin/SPARK-12599.
parent 15bd7362
No related branches found
No related tags found
No related merge requests found
......@@ -115,8 +115,8 @@ abstract class UnaryTransformer[IN, OUT, T <: UnaryTransformer[IN, OUT, T]]
override def transform(dataset: DataFrame): DataFrame = {
transformSchema(dataset.schema, logging = true)
dataset.withColumn($(outputCol),
callUDF(this.createTransformFunc, outputDataType, dataset($(inputCol))))
val transformUDF = udf(this.createTransformFunc, outputDataType)
dataset.withColumn($(outputCol), transformUDF(dataset($(inputCol))))
}
override def copy(extra: ParamMap): T = defaultCopy(extra)
......
......@@ -2843,6 +2843,20 @@ object functions extends LegacyFunctions {
// scalastyle:on parameter.number
// scalastyle:on line.size.limit
/**
* Defines a user-defined function (UDF) using a Scala closure. For this variant, the caller must
* specifcy the output data type, and there is no automatic input type coercion.
*
* @param f A closure in Scala
* @param dataType The output data type of the UDF
*
* @group udf_funcs
* @since 2.0.0
*/
def udf(f: AnyRef, dataType: DataType): UserDefinedFunction = {
UserDefinedFunction(f, dataType, None)
}
/**
* Call an user-defined function.
* Example:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment