開發hive UDF函式

逸卿發表於2015-01-04

from: http://blog.csdn.net/azhao_dn/article/details/6981115


1)首先建立一個java 專案,命名為HelloUDF,使用預設選項;

2)在src目錄上右鍵,選擇建立package,命名為com.test.hive.udf;

3)在package上右鍵,選擇new class,如下圖:

      

    然後在點選Browse,如下圖:

    

      如果你還沒有匯入過hive的jar包,則需要自行匯入:

    右鍵點選java 專案,選擇屬性,如下圖:

   

    再點選 Add External JARS按鈕,如下圖:

   

    選擇所有的jar檔案,點選開啟之後,結果如下圖:

   

   點選ok

4)在輸入完程式碼之後,右鍵Export,如下圖:

    

    

5)到這裡,hive udf就已經開發完成了,將打好的jar包上傳到hive server,然後就可以測試udf了

[html] view plaincopy
  1. hive> add jar /tmp/helloUDF.jar;  
  2.   
  3. hive> create temporary function helloworld as 'com.hrj.hive.udf.HelloUDF';  
  4.   
  5. hive> select helloworld(t.col1) from t limit 10;  
  6.   
  7. hive> drop temporary function helloworld;  

相關文章