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 "方法的描述信息"; } }