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);
        }*/
    }

  • 相关阅读:
    Loadrunner自带协议分析工具:Protocol Advisor
    selenium+python学习总结
    第三篇 HTML 表单及表格
    第二篇 HTML 常用元素及属性值
    第一篇 HTML 认识HTML
    int 问号的使用
    uploadify 上传文件插件
    poj3728 The merchant
    最大公约数
    Bzoj1529/POI2005 ska Piggy banks
  • 原文地址:https://www.cnblogs.com/JBLi/p/10862929.html
Copyright © 2011-2022 走看看