hive GenericUDAF中的四种模式解析
来源:互联网 发布:网络系统建设方案 编辑:程序博客网 时间:2024/05/16 10:18
模式的定义
apache-hive-1.2.1-src\apache-hive-1.2.1-src\ql\src\Java\org\apache\Hadoop\hive\ql\udf\generic\GenericUDAFEvaluator.java
原码如下:
public static enum Mode { /** * PARTIAL1: from original data to partial aggregation data: iterate() and * terminatePartial() will be called. */ PARTIAL1, /** * PARTIAL2: from partial aggregation data to partial aggregation data: * merge() and terminatePartial() will be called. */ PARTIAL2, /** * FINAL: from partial aggregation to full aggregation: merge() and * terminate() will be called. */ FINAL, /** * COMPLETE: from original data directly to full aggregation: iterate() and * terminate() will be called. */ COMPLETE };
UDAF中需要实现的数据处理函数
iterate() 无返回值
terminatePartial() 有返回值
merge() 无返回值
terminate() 有返回值
无返回值的函数叫作aggregate
有返回值的函数叫作evaluate
在代码中的体现是
/** * This function will be called by GroupByOperator when it sees a new input * row. * * @param agg * The object to store the aggregation result. * @param parameters * The row, can be inspected by the OIs passed in init(). */ public void aggregate(AggregationBuffer agg, Object[] parameters) throws HiveException { if (mode == Mode.PARTIAL1 || mode == Mode.COMPLETE) { iterate(agg, parameters); } else { assert (parameters.length == 1); merge(agg, parameters[0]); } } /** * This function will be called by GroupByOperator when it sees a new input * row. * * @param agg * The object to store the aggregation result. */ public Object evaluate(AggregationBuffer agg) throws HiveException { if (mode == Mode.PARTIAL1 || mode == Mode.PARTIAL2) { return terminatePartial(agg); } else { return terminate(agg); } }
四种模式下的输入数据,与可能调用的数据处理函数的关系如下图
每个模式下,输入数据的类型是不会变的,而调用的数据处理函数都有两种可能。
partial1的输入只可能是原始数据;
partial2的输入只可能是部分聚合结果;
final的输入是部分聚合数据;
complete的输入是原始数据;
terminatePartial()与terminate()的输入是有两种可能性的,要按照模式来区分处理。
阅读全文
0 0
- hive GenericUDAF中的四种模式解析
- Hive 中的四种排序
- Hive中的四种排序
- hive中的本地模式
- Android解析四种启动模式
- Activity的四种启动模式解析
- Acticity的四种启动模式解析
- activity四种启动模式简单解析
- Activity四种启动模式解析
- JAVA 中的四种解析XML方式
- JAVA 中的四种解析XML方式
- JAVA 中的四种解析XML方式
- WCF中的四种契约模式
- Activity中的四种启动模式
- shell中的四种模式匹配
- Activity中的四种启动模式
- Activity中的四种启动模式
- Activity中的四种启动模式
- 欢迎使用CSDN-markdown编辑器
- 数据库增加的方法
- hibernate(1)
- ios Cocoapods后的相关错误总结
- MNIST图片可视化(Win7+python3.5)
- hive GenericUDAF中的四种模式解析
- 学历低,不该是穷的理由!
- clojure实战——引述相关'`~~@
- 【学术篇】luogu1558&&poj2777 色板游戏
- 动态规划总结(一)
- 一个帖子学会Android开发四大组件
- 循环读取到数据库
- 树莓派 Raspberry Pi 更换国内源(支持不同发行版本)
- XML、JSON及其解析