配置单元的genericudf在spark上执行两次

lbsnaicq  于 2021-06-26  发布在  Hive
关注(0)|答案(0)|浏览(260)

您好,我在创建配置单元的genericudf并注册为临时函数时遇到了一些问题,但是当我调用它两次时,请参阅下面给出的代码
我用以下代码创建了一个genericudf

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()

它将在evaluate body中执行print语句两次。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题