Github user chenghao-intel commented on a diff in the pull request:
https://github.com/apache/spark/pull/3109#discussion_r20690457
--- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/hiveUdfs.scala
---
@@ -162,9 +161,8 @@ private[hive] case class
HiveGenericUdf(functionClassName: String, children: Seq
(udfType != null && udfType.deterministic())
}
- override def foldable = {
- isUDFDeterministic && children.foldLeft(true)((prev, n) => prev &&
n.foldable)
- }
+ override def foldable =
+ isUDFDeterministic &&
returnInspector.isInstanceOf[ConstantObjectInspector]
--- End diff --
The key change here is we need to get the folded result via Hive the method
`initializeAndFoldConstants` of UDF, not the `initialize` method, that's why I
made the change in L155-L156. UDF itself knows better how to constant fold the
computing if it's applicable, and the return value of
`initializeAndFoldConstants` tells us if it's can be or not and what the result
it is.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]