Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions sql/hive/src/main/scala/org/apache/spark/sql/hive/hiveUdfs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,30 +113,30 @@ private[hive] case class HiveSimpleUdf(functionClassName: String, children: Seq[
classOf[HiveDecimal], java.lang.Byte.TYPE, classOf[java.lang.Byte],
classOf[java.sql.Timestamp]
)
val matchingConstructor = argClass.getConstructors.find { c =>
val matchingConstructors = argClass.getConstructors.filter { c =>
c.getParameterTypes.size == 1 && primitiveClasses.contains(c.getParameterTypes.head)
}

matchingConstructor match {
case Some(constructor) =>
(a: Any) => {
if (matchingConstructors.length == 0) {
(a: Any) => wrap(a)
} else {
(a: Any) => {
if (a == null) {
null
} else {
val constructor = matchingConstructors.find { c =>
c.getParameterTypes.head.getCanonicalName.equals(a.getClass.getCanonicalName)
}.getOrElse(matchingConstructors.head)
logDebug(
s"Wrapping $a of type ${if (a == null) "null" else a.getClass.getName} $constructor.")
s"Wrapping $a of type ${a.getClass.getCanonicalName} $constructor.")
// We must make sure that primitives get boxed java style.
if (a == null) {
null
} else {
constructor.newInstance(a match {
case i: Int => i: java.lang.Integer
case bd: BigDecimal => new HiveDecimal(bd.underlying())
case other: AnyRef => other
}).asInstanceOf[AnyRef]
}
}
case None =>
(a: Any) => a match {
case wrapper => wrap(wrapper)
constructor.newInstance(a match {
case i: Int => i: java.lang.Integer
case bd: BigDecimal => new HiveDecimal(bd.underlying())
case other: AnyRef => other
}).asInstanceOf[AnyRef]
}
}
}
}

Expand Down