0

您好,我在创建 hive 的 genericUDF 并注册为临时函数时遇到了一些问题,但是当我调用它时,它的调用两次,请参见下面给出的代码

我用以下代码创建了一个通用UDF

class GenUDF extends GenericUDF{
   var queryOI: StringObjectInspector = null
   var argumentsOI: Array[ObjectInspector] = null

 override def initialize (arguments: Array[ObjectInspector]):ObjectInspector = {
   /*if (arguments.length == 0) {
     throw new UDFArgumentLengthException("At least one argument must be specified")
   }
   if (!(arguments(0).isInstanceOf[StringObjectInspector])) {
     throw new UDFArgumentException("First argument must be a string")
   }
   queryOI = arguments(0).asInstanceOf[StringObjectInspector]
   argumentsOI = arguments*/
   println("inside initializeweeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")
   return PrimitiveObjectInspectorFactory.javaStringObjectInspector
  }

  override def evaluate (arguments: Array[GenericUDF.DeferredObject]):Object = {
    println("inside generic UDF::::::::::::::::::::::((((((((((((((((((((((((FDDDDDDDDDDDDD:")
    4.toString
  }

  def getDisplayString(children: Array[String]): String = {
    println("inside displayssssssssssssssssssssssssssssssss")
      return "udft"
    }

}

当我用以下语句注册它时

 hiveContext.sql("CREATE TEMPORARY FUNCTION udft AS 'functions.GenUDF'")

当我使用以下命令调用此函数时

select udft()

它将在评估正文中执行打印语句两次。

4

0 回答 0