Github user srowen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/23178#discussion_r237521153
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/expressions/UserDefinedFunction.scala
 ---
    @@ -38,114 +38,108 @@ import org.apache.spark.sql.types.DataType
      * @since 1.3.0
      */
     @Stable
    -case class UserDefinedFunction protected[sql] (
    -    f: AnyRef,
    -    dataType: DataType,
    -    inputTypes: Option[Seq[DataType]]) {
    -
    -  private var _nameOption: Option[String] = None
    -  private var _nullable: Boolean = true
    -  private var _deterministic: Boolean = true
    -
    -  // This is a `var` instead of in the constructor for backward 
compatibility of this case class.
    -  // TODO: revisit this case class in Spark 3.0, and narrow down the 
public surface.
    -  private[sql] var nullableTypes: Option[Seq[Boolean]] = None
    +trait UserDefinedFunction {
     
       /**
        * Returns true when the UDF can return a nullable value.
        *
        * @since 2.3.0
        */
    -  def nullable: Boolean = _nullable
    +  def nullable: Boolean
     
       /**
        * Returns true iff the UDF is deterministic, i.e. the UDF produces the 
same output given the same
        * input.
        *
        * @since 2.3.0
        */
    -  def deterministic: Boolean = _deterministic
    +  def deterministic: Boolean
     
       /**
        * Returns an expression that invokes the UDF, using the given arguments.
        *
        * @since 1.3.0
        */
       @scala.annotation.varargs
    -  def apply(exprs: Column*): Column = {
    +  def apply(exprs: Column*): Column
    +
    +  /**
    +   * Updates UserDefinedFunction with a given name.
    +   *
    +   * @since 2.3.0
    +   */
    +  def withName(name: String): UserDefinedFunction
    +
    +  /**
    +   * Updates UserDefinedFunction to non-nullable.
    +   *
    +   * @since 2.3.0
    +   */
    +  def asNonNullable(): UserDefinedFunction
    +
    +  /**
    +   * Updates UserDefinedFunction to nondeterministic.
    +   *
    +   * @since 2.3.0
    +   */
    +  def asNondeterministic(): UserDefinedFunction
    +}
    +
    +private[sql] case class SparkUserDefinedFunction(
    +    f: AnyRef,
    +    dataType: DataType,
    +    inputTypes: Option[Seq[DataType]],
    +    nullableTypes: Option[Seq[Boolean]],
    +    name: Option[String] = None,
    +    nullable: Boolean = true,
    +    deterministic: Boolean = true) extends UserDefinedFunction {
    +
    +  @scala.annotation.varargs
    +  override def apply(exprs: Column*): Column = {
         // TODO: make sure this class is only instantiated through 
`SparkUserDefinedFunction.create()`
         // and `nullableTypes` is always set.
    -    if (nullableTypes.isEmpty) {
    -      nullableTypes = Some(ScalaReflection.getParameterTypeNullability(f))
    -    }
         if (inputTypes.isDefined) {
           assert(inputTypes.get.length == nullableTypes.get.length)
         }
     
    +    val inputsNullSafe = if (nullableTypes.isEmpty) {
    --- End diff --
    
    You can use `getOrElse` here and even inline this into the call below, but 
I don't really care.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to