Class UserDefinedFunction

Object
org.apache.spark.sql.expressions.UserDefinedFunction

public abstract class UserDefinedFunction extends Object
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 Details

    • UserDefinedFunction

      public UserDefinedFunction()
  • Method Details

    • apply

      public Column apply(Column... exprs)
      Returns an expression that invokes the UDF, using the given arguments.

      Parameters:
      exprs - (undocumented)
      Returns:
      (undocumented)
      Since:
      1.3.0
    • apply

      public abstract Column apply(scala.collection.Seq<Column> exprs)
      Returns an expression that invokes the UDF, using the given arguments.

      Parameters:
      exprs - (undocumented)
      Returns:
      (undocumented)
      Since:
      1.3.0
    • asNonNullable

      public abstract UserDefinedFunction asNonNullable()
      Updates UserDefinedFunction to non-nullable.

      Returns:
      (undocumented)
      Since:
      2.3.0
    • asNondeterministic

      public abstract UserDefinedFunction 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

      public abstract UserDefinedFunction withName(String name)
      Updates UserDefinedFunction with a given name.

      Parameters:
      name - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.3.0