HIVE的UDF

开启本地hive运行界面 需要配置本地mysql用户hive

创建本地hive数据库在mysql中,增加hive用户的权限

eclipse中导入hive的jar包

 

import org.apache.hadoop.hive.cli.CliDriver;

/**
 * 开启本地hive运行界面
 * @author   IT_BULL                      
 * @Date     2018年7月10日      
 */
public class HiveDriver {

    public static void main(String[] args) throws Exception {

        System.setProperty("jline.WindowsTerminal.directConsole", "false");
         int ret = new CliDriver().run(args);
            System.exit(ret);
    }
}

 

开始写UDF函数

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

/**
 * 自定义UDF
 * @author   IT_BULL                      
 * @Date     2018年7月10日      
 */
public class Lower extends UDF {
    public String evaluate(String s) {
        if(null != s) {
            return s.toLowerCase();
        }
        return null;
    }
}

 

开始运行:

--加载自定义函数
create temporary function toto as 'com.it.Localhive.UDF.Lower';
--测试自定义函数
select toto('ABCDEFG');

 

 

posted @ 2018-07-11 11:12  马鞍山  阅读(103)  评论(0编辑  收藏  举报