Hive UDF開發


Hive進行UDF開發十分簡單,此處所說UDF為Temporary的function,所以需要hive版本在0.4.0以上才可以。

Hive的UDF開發只需要重構UDF類的evaluate函數即可。例:

package com.hrj.hive.udf;

import org.apache.hadoop.hive.ql.exec.UDF;

public class helloUDF extends UDF {

    public String evaluate(String str) {

        try {

            return "HelloWorld " + str;

        } catch (Exception e) {

            return null;

        }

    }

 

將該java文件編譯成helloudf.jar

hive> add jar helloudf.jar;

hive> create temporary function helloworld as 'com.hrj.hive.udf.helloUDF';

hive> select helloworld(t.col1) from t limit 10;

hive> drop temporary function helloworld;

 

注:

1.helloworld為臨時的函數,所以每次進入hive都需要add jar以及create temporary操作

2.UDF只能實現一進一出的操作,如果需要實現多進一出,則需要實現UDAF


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM