HIVE: UDF应用实例

数据文件内容

TEST DATA HERE
Good to Go

我们准备写一个函数,把所有字符变为小写.

 

1.开发UDF

package MyTestPackage;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;

public class ToLowerCase extends UDF 
 {
    public Text evaluate(final Text s)
    {
        return new Text(s.toString().toLowerCase());
    }

}

 

2.打包为MyUDF.jar

3.hive> add jar /home/work/MyUDF.jar;

4.hive> create temporary function mytest as 'MyTestPackage.ToLowerCase';

5.hive> show functions;

已经加好了

6.HQL中使用-

 

posted @ 2015-05-14 00:02  Ready!  阅读(1068)  评论(0编辑  收藏  举报