zoukankan      html  css  js  c++  java
  • 自定义函数

    add jar /root/Downloads/apache-hive-1.2.0-bin/lib/udf.jar;

    1.引jar  写自己想用的方法

    2.将jar  放入hive中的lib下

    3.创建一个临时的方法 

    create temporary function allsal as "com.bw.hive.function";

    4.查询sql结果

    package com.bw.hive;
    
    import org.apache.hadoop.hive.ql.exec.UDF;
    //用户自定义函数
    public class function extends UDF{
        //在hive的udf 中每个执行的函数都叫做evaluate
        //salary*12+bonus
        public Double evaluate(Double a,Double b) {
            Double salary=0.0;
            Double comm=0.0;
            if(a!=null) {
                salary=a;
                
            }
            
            if(b!=null) {
                comm=b;
            }
            return 12*salary+comm;
            
        }
    }

     

     

     

     ==========================================================================================================

    ==============================================================

     

    create temporary function myconcat as "com.bw.hive.function";

    //注意 要重新退出一下 再进一下hive

    package com.bw.hive;
    
    import org.apache.hadoop.hive.ql.exec.UDF;
    //用户自定义函数
    public class function extends UDF{
        //在hive的udf 中每个执行的函数都叫做evaluate
        //salary*12+bonus
        public Double evaluate(Double a,Double b) {
            Double salary=0.0;
            Double comm=0.0;
            if(a!=null) {
                salary=a;
                
            }
            
            if(b!=null) {
                comm=b;
            }
            return 12*salary+comm;
        }
        
        public String evaluate(String ...words) {
            if(words.length==1) {
                return words[0];
            }else {
                String result="";
                for(String s:words) {
                    result+=" "+s;
                }
                return result.replaceFirst(" ","");
            }
        }
        //xxxx(1,2,3,4..........) 1 2 3 4 5 
        /*public String evaluate() {
            return null;
        }*/
        //aa(String[]args)   String[] strs={1,2,3,4,5} aa(strs)
                //bb(String ....args)  bb(1)  bb(1,2,3,4) bb(1,2,3,4)
        /*public static void aa(int[] arr) {}
        public static void bb(int ...args) {}
        public static void main(String[] args) {
            int[] abc= {1,2,3,4,5};
            aa(abc);
            bb(1,2,3,4,5);
        }*/
    }

  • 相关阅读:
    notepad++插件 small
    js中面向对象 small
    #九阴真经#优选配置渲染流程简要分析[Flexi引擎]
    gkENGINE HDR流程简析
    新的开始
    以前的一些画
    gkENGINE 开发两年半总结(上)
    gkENGINE跨平台的问题总结
    win7下安装xp双系统
    Hadoop0.20.2+ Nutch1.2+Tomcat7——分布式搜索配置
  • 原文地址:https://www.cnblogs.com/JBLi/p/10862929.html
Copyright © 2011-2022 走看看