zoukankan      html  css  js  c++  java
  • Hive创建一个简单的UDF

    创建一个类

    package com.dufeng.hive;
    
    import org.apache.commons.lang.StringUtils;
    import org.apache.hadoop.hive.ql.exec.UDF;
    import org.apache.hadoop.io.Text;
    
    /**
     * Hello world!
     *
     */
    public class Dufeng extends UDF {
        
        private Text result = new Text();
        
        public Text evaluate(Text str, String stripChars) {
            if (str == null) {
                return null;
            }
            
            result.set(StringUtils.strip(str.toString(), stripChars));
            return result;
        }
        
        
        public Text evaluate(Text str) {
            if (str == null) {
                return null;
            }
            
            result.set("hello " + StringUtils.strip(str.toString()));
            return result;
        }
    }

    用Maven构建成jar包

    maven clean install package

    打开hive shell控制台

    hive> add jar /home/hive/dufengHive-0.0.1-SNAPSHOT.jar;
    Added [/home/hive/dufengHive-0.0.1-SNAPSHOT.jar] to class path
    Added resources: [/home/hive/dufengHive-0.0.1-SNAPSHOT.jar]
    hive> list jars;
    /home/hive/dufengHive-0.0.1-SNAPSHOT.jar
    hive> create temporary function dufeng as 'com.dufeng.hive.Dufeng';
    OK
    Time taken: 0.382 seconds
    hive> select dufeng('sss') from employee;
    OK
    hello sss
    hello sss
    hello sss
    hello sss
    hello sss
    hello sss
    hello sss
    hello sss
    hello sss
    hive> select dufeng('hadoop', 'ha') from employee;
    OK
    doop
    doop
    doop
    doop
    doop
    doop
    doop
    doop
    doop
    Time taken: 0.178 seconds, Fetched: 9 row(s)


  • 相关阅读:
    鼠标放在图片上出现提示
    NSIS调用dll
    IIS7 CMD命令
    NSIS检测
    NSIS修改文件夹访问权限
    NSIS——检测IIS是否安装及版本
    NSIS——检测SQL Server安装版本
    NSIS使用技巧集合
    提供修复界面的NSIS安装包
    NSIS MUI教程
  • 原文地址:https://www.cnblogs.com/yandufeng/p/6437163.html
Copyright © 2011-2022 走看看