Package org.apache.spark.sql.expressions
Class UserDefinedFunction
Object
org.apache.spark.sql.expressions.UserDefinedFunction
A user-defined function. To create one, use the
udf
functions in functions
.
As an example:
// Define a UDF that returns true or false based on some numeric score.
val predict = udf((score: Double) => score > 0.5)
// Projects a column that adds a prediction column based on the score column.
df.select( predict(df("score")) )
- Since:
- 1.3.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns an expression that invokes the UDF, using the given arguments.abstract Column
Returns an expression that invokes the UDF, using the given arguments.abstract UserDefinedFunction
Updates UserDefinedFunction to nondeterministic.abstract UserDefinedFunction
Updates UserDefinedFunction to non-nullable.abstract boolean
Returns true iff the UDF is deterministic, i.e. the UDF produces the same output given the same input.abstract boolean
nullable()
Returns true when the UDF can return a nullable value.abstract UserDefinedFunction
Updates UserDefinedFunction with a given name.
-
Constructor Details
-
UserDefinedFunction
public UserDefinedFunction()
-
-
Method Details
-
apply
Returns an expression that invokes the UDF, using the given arguments.- Parameters:
exprs
- (undocumented)- Returns:
- (undocumented)
- Since:
- 1.3.0
-
apply
Returns an expression that invokes the UDF, using the given arguments.- Parameters:
exprs
- (undocumented)- Returns:
- (undocumented)
- Since:
- 1.3.0
-
asNonNullable
Updates UserDefinedFunction to non-nullable.- Returns:
- (undocumented)
- Since:
- 2.3.0
-
asNondeterministic
Updates UserDefinedFunction to nondeterministic.- Returns:
- (undocumented)
- Since:
- 2.3.0
-
deterministic
public abstract boolean deterministic()Returns true iff the UDF is deterministic, i.e. the UDF produces the same output given the same input.- Returns:
- (undocumented)
- Since:
- 2.3.0
-
nullable
public abstract boolean nullable()Returns true when the UDF can return a nullable value.- Returns:
- (undocumented)
- Since:
- 2.3.0
-
withName
Updates UserDefinedFunction with a given name.- Parameters:
name
- (undocumented)- Returns:
- (undocumented)
- Since:
- 2.3.0
-