hive UDAF

java 程序
package com.ibeifeng.udaf; import org.apache.hadoop.hive.ql.exec.UDAF;
import org.apache.hadoop.hive.ql.exec.UDAFEvaluator; public class Wm_concat extends UDAF { public static class MYUDAFVAL implements UDAFEvaluator{ private PartialResult partial = new PartialResult();
public static class PartialResult{
String result = "";
String delilmiter = null;
}
@Override
public void init() {
// TODO 自动生成的方法存根
partial.result = ""; }
public boolean iterate(String value, String deli){
if(value == null || "null".equalsIgnoreCase(value)){
return true;
}
if(partial.delilmiter == null){
partial.delilmiter = deli; }
if(partial.result.length() > 0){ partial.result = partial.result.concat(partial.delilmiter); } partial.result = partial.result.concat(value); return true; } public PartialResult terminatePartial(){ return partial;
} public boolean merge(PartialResult other){ if(other == null)
return true;
if(partial.delilmiter == null){
partial.delilmiter = other.delilmiter;
partial.result = other.result;
}else{
if(partial.result.length()>0){
partial.result = partial.result.concat(partial.delilmiter); }
partial.result = partial.result.concat(other.result); }
return true; }
public String terminate(){ if(partial == null || partial.result == null){ return null;
}
return partial.result;
}
} }
hive UDAF的更多相关文章
- Hive UDAF开发之同时计算最大值与最小值
卷首语 前一篇文章hive UDAF开发入门和运行过程详解(转)里面讲过UDAF的开发过程,其中说到如果要深入理解UDAF的执行,可以看看求平均值的UDF的源码 本人在看完源码后,也还是没能十分理解里 ...
- Hive UDAF开发详解
说明 这篇文章是来自Hadoop Hive UDAF Tutorial - Extending Hive with Aggregation Functions:的不严格翻译,因为翻译的文章示例写得比较 ...
- Hive UDAF介绍与开发
UDAF简介 UDAF是用户自定义聚合函数.Hive支持其用户自行开发聚合函数完成业务逻辑. 通俗点说,就是你可能需要做一些特殊的甚至是非常扭曲的逻辑聚合,但是Hive自带的聚合函数不够玩,同时也还找 ...
- hive UDAF源代码分析
sss /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license a ...
- hive UDAF开发入门和运行过程详解(转)
介绍 hive的用户自定义聚合函数(UDAF)是一个很好的功能,集成了先进的数据处理.hive有两种UDAF:简单和通用.顾名思义,简单的UDAF,写的相当简单的,但因为使用Java反射导致性能损失, ...
- DeveloperGuide Hive UDAF
Writing GenericUDAFs: A Tutorial User-Defined Aggregation Functions (UDAFs) are an excellent way to ...
- 自定义Hive UDAF 实现相邻去重
内置的两个聚合函数(UDAF) collect_list():多行字符串拼接为一行collect_set():多行字符串拼接为一行并去重多行字符串拼接为一行并相邻去重UDAF:Concat() con ...
- hive UDAF开发和运行全过程
介绍 hive的用户自定义聚合函数(UDAF)是一个很好的功能,集成了先进的数据处理.hive有两种UDAF:简单和通用.顾名思义,简单的UDAF,写的相当简单的,但因为使用Java反射导致性能损失, ...
- hive udaf 用maven打包运行create temporary function 时报错
用maven打包写好的jar,在放到hive中作暂时函数时报错. 错误信息例如以下: hive> create temporary function maxvalue as "com. ...
随机推荐
- lintcode:Matrix Zigzag Traversal 矩阵的之字型遍历
题目: 矩阵的之字型遍历 给你一个包含 m x n 个元素的矩阵 (m 行, n 列), 求该矩阵的之字型遍历. 样例 对于如下矩阵: [ [1, 2, 3, 4], [5, 6, 7, 8], [9 ...
- ASP.Net WebForm学习笔记:一、aspx与服务器控件探秘
作者:周旭龙 出处:http://edisonchou.cnblogs.com 开篇:毫无疑问,ASP.Net WebForm是微软推出的一个跨时代的Web开发模式,它将WinForm开发模式的快捷便 ...
- Orcle数据库编程:一
1.PL/SQL是一种块结构的语言,一个PL/SQL程序包含了一个或者多个逻辑块,逻辑块中可以声明变量,变量在使用之前必须先声明. declare mstu student%ROWTYPE;--定义参 ...
- ADO.NET入门教程(三) 连接字符串,你小觑了吗?
出处:http://www.cnblogs.com/liuhaorain/archive/2012/02/12/2347914.html 摘要 ADO.NET强大的优势在于对不同的数据源提供一致的访问 ...
- Python中的两种结构dict和set
Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度. 假设要根据同学的名字查找对应的成绩 如果 ...
- 246. Strobogrammatic Number
题目: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at ups ...
- cmd命令行指定系统延迟关机时间
shutdown -s -t 3600 -c "想要显示的注释" -f 各参数的意思:-s 动作为关机 -t 3600 延迟3600秒关机 -c "想要显示的注释&quo ...
- newClass a = Func(3)中隐藏的操作
缘起 #include <iostream> #include <bitset> using namespace std; class A { public: A() { co ...
- Win8-64位安装OpenSSL详细过程
相关软件: 1.ActivePerl 5.22.1 : http://www.activestate.com/activeperl/downloads 2.Microsoft visual_studi ...
- 10位顶级PHP大师的开发原则
在Web开发世界里,PHP是最流行的语言之一,从PHP里,你能够很容易的找到你所需的脚本,遗憾的是,很少人会去用“最佳做法”去写一个PHP程序.这里,我们向大家介绍PHP的10种最佳实践,当然,每一种 ...