ITPub博客

首页 > 大数据 > Hadoop > Hive UDF开发

Hive UDF开发

原创 Hadoop 作者:xinlieboy 时间:2014-11-22 11:03:58 0 删除 编辑

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

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26495863/viewspace-1342360/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: mysql 导入CSV数据
请登录后发表评论 登录
全部评论

注册时间:2012-11-22

  • 博文量
    65
  • 访问量
    316109