Skip to content

Commit

Permalink
Type coercion for udf inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheolsoo Park committed Jul 3, 2015
1 parent d983819 commit 066deed
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ object HiveTypeCoercion {
// Skip nodes who's children have not been resolved yet.
case e if !e.childrenResolved => e

case e: ExpectsInputTypes =>
case e: ExpectsInputTypes if (e.inputTypes.nonEmpty) =>
val children: Seq[Expression] = e.children.zip(e.inputTypes).map { case (in, expected) =>
implicitCast(in, expected)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ import org.apache.spark.sql.types.DataType
* User-defined function.
* @param dataType Return type of function.
*/
case class ScalaUDF(function: AnyRef, dataType: DataType, children: Seq[Expression])
extends Expression {
case class ScalaUDF(
function: AnyRef,
dataType: DataType,
children: Seq[Expression],
expectedInputTypes: Seq[DataType] = Nil) extends Expression with ExpectsInputTypes {

override def nullable: Boolean = true

override def toString: String = s"UDF(${children.mkString(",")})"

override def inputTypes: Seq[DataType] = expectedInputTypes

// scalastyle:off

/** This method has been generated by this script
Expand Down
Loading

0 comments on commit 066deed

Please sign in to comment.