@@ -33,43 +33,51 @@ import org.apache.hadoop.hive.ql.udf.generic.GenericUDFUtils.ConversionHelper
3333import org .apache .spark .Logging
3434import org .apache .spark .sql .AnalysisException
3535import org .apache .spark .sql .catalyst .analysis
36+ import org .apache .spark .sql .catalyst .analysis .FunctionRegistry .FunctionBuilder
3637import org .apache .spark .sql .catalyst .errors .TreeNodeException
3738import org .apache .spark .sql .catalyst .expressions ._
3839import org .apache .spark .sql .catalyst .plans .logical ._
3940import org .apache .spark .sql .catalyst .rules .Rule
4041import org .apache .spark .sql .hive .HiveShim ._
4142import org .apache .spark .sql .types ._
4243
44+ import scala .util .Try
4345
44- private [hive] abstract class HiveFunctionRegistry
46+
47+ private [hive] class HiveFunctionRegistry (underlying : analysis.FunctionRegistry )
4548 extends analysis.FunctionRegistry with HiveInspectors {
4649
4750 def getFunctionInfo (name : String ): FunctionInfo = FunctionRegistry .getFunctionInfo(name)
4851
4952 override def lookupFunction (name : String , children : Seq [Expression ]): Expression = {
50- // We only look it up to see if it exists, but do not include it in the HiveUDF since it is
51- // not always serializable.
52- val functionInfo : FunctionInfo =
53- Option (FunctionRegistry .getFunctionInfo(name.toLowerCase)).getOrElse(
54- throw new AnalysisException (s " undefined function $name" ))
55-
56- val functionClassName = functionInfo.getFunctionClass.getName
57-
58- if (classOf [UDF ].isAssignableFrom(functionInfo.getFunctionClass)) {
59- HiveSimpleUdf (new HiveFunctionWrapper (functionClassName), children)
60- } else if (classOf [GenericUDF ].isAssignableFrom(functionInfo.getFunctionClass)) {
61- HiveGenericUdf (new HiveFunctionWrapper (functionClassName), children)
62- } else if (
63- classOf [AbstractGenericUDAFResolver ].isAssignableFrom(functionInfo.getFunctionClass)) {
64- HiveGenericUdaf (new HiveFunctionWrapper (functionClassName), children)
65- } else if (classOf [UDAF ].isAssignableFrom(functionInfo.getFunctionClass)) {
66- HiveUdaf (new HiveFunctionWrapper (functionClassName), children)
67- } else if (classOf [GenericUDTF ].isAssignableFrom(functionInfo.getFunctionClass)) {
68- HiveGenericUdtf (new HiveFunctionWrapper (functionClassName), children)
69- } else {
70- sys.error(s " No handler for udf ${functionInfo.getFunctionClass}" )
53+ Try (underlying.lookupFunction(name, children)).getOrElse {
54+ // We only look it up to see if it exists, but do not include it in the HiveUDF since it is
55+ // not always serializable.
56+ val functionInfo : FunctionInfo =
57+ Option (FunctionRegistry .getFunctionInfo(name.toLowerCase)).getOrElse(
58+ throw new AnalysisException (s " undefined function $name" ))
59+
60+ val functionClassName = functionInfo.getFunctionClass.getName
61+
62+ if (classOf [UDF ].isAssignableFrom(functionInfo.getFunctionClass)) {
63+ HiveSimpleUdf (new HiveFunctionWrapper (functionClassName), children)
64+ } else if (classOf [GenericUDF ].isAssignableFrom(functionInfo.getFunctionClass)) {
65+ HiveGenericUdf (new HiveFunctionWrapper (functionClassName), children)
66+ } else if (
67+ classOf [AbstractGenericUDAFResolver ].isAssignableFrom(functionInfo.getFunctionClass)) {
68+ HiveGenericUdaf (new HiveFunctionWrapper (functionClassName), children)
69+ } else if (classOf [UDAF ].isAssignableFrom(functionInfo.getFunctionClass)) {
70+ HiveUdaf (new HiveFunctionWrapper (functionClassName), children)
71+ } else if (classOf [GenericUDTF ].isAssignableFrom(functionInfo.getFunctionClass)) {
72+ HiveGenericUdtf (new HiveFunctionWrapper (functionClassName), children)
73+ } else {
74+ sys.error(s " No handler for udf ${functionInfo.getFunctionClass}" )
75+ }
7176 }
7277 }
78+
79+ override def registerFunction (name : String , builder : FunctionBuilder ): Unit =
80+ throw new UnsupportedOperationException
7381}
7482
7583private [hive] case class HiveSimpleUdf (funcWrapper : HiveFunctionWrapper , children : Seq [Expression ])
0 commit comments