zoukankan      html  css  js  c++  java
  • LowerUDF

    package com.XX.udf;
    
    
    import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
    import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
    import org.apache.hadoop.hive.ql.metadata.HiveException;
    import org.apache.hadoop.hive.ql.udf.generic.GenericUDF;
    import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
    import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
    import org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector;
    
    
    public class LowerUDF extends GenericUDF {
    
        StringObjectInspector str ;
        @Override
        public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
            //判断输入参数个数是否合法
            if (arguments.length != 1) {
                throw new UDFArgumentLengthException("输入参数长度不合法,应该为一个参数");
            }
    
            //判断输入参数类型是否合法
            if (!(arguments[0] instanceof StringObjectInspector)) {
                throw new UDFArgumentException("输入非法参数,应为字符串类型");
            }
    
            str=(StringObjectInspector)arguments[0];
            //制定输出类型
            return PrimitiveObjectInspectorFactory.javaStringObjectInspector;
        }
    
        @Override
        public Object evaluate(DeferredObject[] arguments) throws HiveException {
            String input = str.getPrimitiveJavaObject(arguments[0].get());
            return input.toLowerCase();
        }
    
        @Override
        public String getDisplayString(String[] children) {
            return "方法的描述信息";
        }
    }
  • 相关阅读:
    单链表反转的2种常见方法
    LeetCode解题报告:Reorder List
    LeetCode解题报告:Binary Tree Postorder Traversal
    LeetCode解题报告:LRU Cache
    LeetCode解题报告:Insertion Sort List
    Java编程杂记
    如何对一个不断更新的HashMap进行排序
    Python快速入门
    Html与CSS快速入门01-基础概念
    JVM快速入门
  • 原文地址:https://www.cnblogs.com/yin-fei/p/10879725.html
Copyright © 2011-2022 走看看