Skip to content

Commit

Permalink
[SPARK-20668][SQL] Modify ScalaUDF to handle nullability.
Browse files Browse the repository at this point in the history
## What changes were proposed in this pull request?

When registering Scala UDF, we can know if the udf will return nullable value or not. `ScalaUDF` and related classes should handle the nullability.

## How was this patch tested?

Existing tests.

Author: Takuya UESHIN <ueshin@databricks.com>

Closes apache#17911 from ueshin/issues/SPARK-20668.
  • Loading branch information
ueshin authored and liyichao committed May 24, 2017
1 parent 1ebbc22 commit 68f6527
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2128,7 +2128,7 @@ class Analyzer(

case p => p transformExpressionsUp {

case udf @ ScalaUDF(func, _, inputs, _, _) =>
case udf @ ScalaUDF(func, _, inputs, _, _, _) =>
val parameterTypes = ScalaReflection.getParameterTypes(func)
assert(parameterTypes.length == inputs.length)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ import org.apache.spark.sql.types.DataType
* better to use Option of Seq[DataType] so we can use "None" as the case for no
* type coercion. However, that would require more refactoring of the codebase.
* @param udfName The user-specified name of this UDF.
* @param nullable True if the UDF can return null value.
*/
case class ScalaUDF(
function: AnyRef,
dataType: DataType,
children: Seq[Expression],
inputTypes: Seq[DataType] = Nil,
udfName: Option[String] = None)
udfName: Option[String] = None,
nullable: Boolean = true)
extends Expression with ImplicitCastInputTypes with NonSQLExpression {

override def nullable: Boolean = true

override def toString: String =
s"${udfName.map(name => s"UDF:$name").getOrElse("UDF")}(${children.mkString(", ")})"

Expand Down
Loading

0 comments on commit 68f6527

Please sign in to comment.