wangyum commented on a change in pull request #30665:
URL: https://github.com/apache/spark/pull/30665#discussion_r539308795
##########
File path:
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveSessionCatalog.scala
##########
@@ -91,8 +91,18 @@ private[sql] class HiveSessionCatalog(
isUDAFBridgeRequired = true))
udfExpr.get.dataType // Force it to check input data types.
} else if (classOf[GenericUDTF].isAssignableFrom(clazz)) {
- udfExpr = Some(HiveGenericUDTF(name, new
HiveFunctionWrapper(clazz.getName), input))
- udfExpr.get.asInstanceOf[HiveGenericUDTF].elementSchema // Force
it to check data types.
+ try {
+ udfExpr = Some(HiveGenericUDTF(name, new
HiveFunctionWrapper(clazz.getName), input))
+ // Force it to check input data types.
+ udfExpr.get.asInstanceOf[HiveGenericUDTF].elementSchema
+ } catch {
+ case exception: Exception =>
+ logInfo(s"HiveGenericUDTF initialize(ObjectInspector[] args)
is deprecated, and" +
+ s" we will suit the latest version of
initialize(StructObjectInspector argOIs).")
+ udfExpr = Some(HiveGenericUDTF(name, new
HiveFunctionWrapper(clazz.getName),
+ input, false))
+ udfExpr.get.asInstanceOf[HiveGenericUDTF].elementSchema
Review comment:
How about?
```scala
val funcWrapper = new HiveFunctionWrapper(clazz.getName)
try {
udfExpr = Some(HiveGenericUDTF(name, funcWrapper, input, true))
// Force it to check data types.
udfExpr.get.asInstanceOf[HiveGenericUDTF].elementSchema
} catch {
case e: IllegalStateException if e.getMessage.equals("Should not be called
directly") =>
logInfo("Fallback to use the non deprecated UDTF constructor.")
udfExpr = Some(HiveGenericUDTF(name, funcWrapper, input, false))
// Force it to check data types.
udfExpr.get.asInstanceOf[HiveGenericUDTF].elementSchema
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]