Skip to content

Commit a18f917

Browse files
committed
avoid constant udf expression re-evaluation
- fixes failure due to return iterator and value type mismatch
1 parent c46db0f commit a18f917

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/hiveUdfs.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ private[hive] case class HiveGenericUdf(functionClassName: String, children: Seq
164164
override def foldable =
165165
isUDFDeterministic && returnInspector.isInstanceOf[ConstantObjectInspector]
166166

167+
@transient
168+
protected lazy val constantReturnValue = unwrap(
169+
returnInspector.asInstanceOf[ConstantObjectInspector].getWritableConstantValue(),
170+
returnInspector)
171+
167172
@transient
168173
protected lazy val deferedObjects =
169174
argumentInspectors.map(new DeferredObjectAdapter(_)).toArray[DeferredObject]
@@ -172,6 +177,8 @@ private[hive] case class HiveGenericUdf(functionClassName: String, children: Seq
172177

173178
override def eval(input: Row): Any = {
174179
returnInspector // Make sure initialized.
180+
if(foldable) return constantReturnValue
181+
175182
var i = 0
176183
while (i < children.length) {
177184
val idx = i

0 commit comments

Comments
 (0)