java中
可以使用的方法java_method(类,方法[__arg1[,最长…]])或者反映
用户定义表函数(表函数)一行变成多行配合侧视
蜂巢的Lateral 查看http://blog.sina.com.cn/s/blog_7e04e0d00101csic.html
import org.apache.hadoop.hive.ql.exec.UDF; import org.apache.hadoop.io.Text; public class  udftest extends  UDF { ,,,public boolean 评估(Text  Text t1, t2) { ,,,,,,,如果(t1==null | | t2==null) { ,,,,,,,,,,,return 假; ,,,,,,,} ,,,,,,,double d1=Double.parseDouble (t1.toString ()); ,,,,,,,double d2=Double.parseDouble (t2.toString ()); ,,,,,,,如果(d1> d2) { ,,,,,,,,,,,return 真实; ,,,,,,,其他}{ ,,,,,,,,,,, ,,,,,,,,,,,return 假; ,,,,,,,} ,,,, ,,,} }
函数打包成函数。jar
蜂巢命令行
add jar /home/jar/function.jar ,//jar包进入分布式缓存 create temporary  function bigthan as  com.peixun.udf。udftest '//执行创建模版函数辟探
30的记录个数countbigthan (b, 30)实现代码强>
import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException; import org.apache.hadoop.hive.ql.metadata.HiveException; import org.apache.hadoop.hive.ql.parse.SemanticException; import org.apache.hadoop.hive.ql.udf.generic.AbstractGenericUDAFResolver; import org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator, import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo; import org.apache.hadoop.io.LongWritable;//继承类型检查类 public class  udaftest extends AbstractGenericUDAFResolver  { ,,,//,参数个数判断 ,,@Override ,,,public GenericUDAFEvaluator getEvaluator (TypeInfo[],参数) ,,,,,,,,,,,throws SemanticException { ,,,,,,,if (parameters.length !=, 2), { ,,,,,,,,,,,throw new UDFArgumentTypeException (parameters.length 安康;1, ,,,,,,,,,,,,,,,,,,,”Exactly two  argument is 预期”); ,,,,,,,} ,,,,,,,return new GenericUDAFCountBigThanEvaluator();//,返回处理逻辑类 ,,,} ,,,//,处理逻辑类 ,,,public static class GenericUDAFCountBigThanEvaluator 延伸 ,,,,,,,,,,,GenericUDAFEvaluator { ,,,,,,,private LongWritable 结果; ,,,,,,,private PrimitiveObjectInspector inputOI1; ,,,,,,,private PrimitiveObjectInspector inputOI2; ,,,,,,,//,初始化方法图,减少阶段都得执行 ,,,,,,,//,地图阶段参数长度与UDAF输入的参数个数有关 ,,,,,,,//,减少阶段,参数长度为1 ,,,,,,@Override null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null蜂巢混合函数UDTF UDF UDAF详解