Skip to content

Commit c96b512

Browse files
author
Davies Liu
committed
add test
1 parent c0f85bb commit c96b512

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ScalaUDF.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,8 +1032,8 @@ case class ScalaUDF(
10321032
val funcArguments = converterTerms.zipWithIndex.map {
10331033
case (converter, i) =>
10341034
val eval = evals(i)
1035-
val boxedType = ctx.boxedType(children(i).dataType)
1036-
s"$converter.apply(${eval.isNull} ? ($boxedType) null : ($boxedType) ${eval.value})"
1035+
val dt = children(i).dataType
1036+
s"$converter.apply(${eval.isNull} ? null : (${ctx.boxedType(dt)})(${eval.value}))"
10371037
}.mkString(",")
10381038
val callFunc = s"${ctx.boxedType(ctx.javaType(dataType))} $resultTerm = " +
10391039
s"(${ctx.boxedType(ctx.javaType(dataType))})${catalystConverterTerm}" +

sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,9 @@ class DataFrameSuite extends QueryTest with SharedSQLContext {
11481148
}
11491149
checkAnswer(df.select(boxedUDF($"age")), Row(44) :: Row(-10) :: Nil)
11501150

1151+
sqlContext.udf.register("boxedUDF", (i: java.lang.Integer) => if (i == null) -10 else i * 2)
1152+
checkAnswer(sql("select boxedUDF(null), boxedUDF(-1)"), Row(-10, -2) :: Nil)
1153+
11511154
val primitiveUDF = udf((i: Int) => i * 2)
11521155
checkAnswer(df.select(primitiveUDF($"age")), Row(44) :: Row(null) :: Nil)
11531156
}

0 commit comments

Comments
 (0)