hive基于UDAF的编写
程序员文章站
2022-03-31 18:17:21
...
------------- select concat(account,'\t',bfdutmb,'\t',page_url) from ( select account,bfdutmb,actionPath(page_url,'->') page_url from ( select create_time,account,bfdutmb,page_url page_url from ods_action_event order by account,bfdutmb,create_time)c group by account,bfdutmb)b
import org.apache.hadoop.hive.ql.exec.UDAF; import org.apache.hadoop.hive.ql.exec.UDAFEvaluator; public class ActionPathUDAF extends UDAF { public static class ConcatUDAFEvaluator implements UDAFEvaluator { public static class PartialResult { String result; String delimiter; } private PartialResult partial; public void init() { partial = null; } public boolean iterate(String value, String deli) { if (value == null) { return true; } if (partial == null) { partial = new PartialResult(); partial.result = new String(""); if (deli == null || deli.equals("")) { partial.delimiter = new String(","); } else { partial.delimiter = new String(deli); } } if (partial.result.length() > 0) { partial.result = partial.result.concat(partial.delimiter);//result='aa',delimiter='->' | aa-> } 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 == null) { partial = new PartialResult(); partial.result = new String(other.result); partial.delimiter = new String(other.delimiter); } else { if (partial.result.length() > 0) { partial.result = partial.result.concat(partial.delimiter); } partial.result = partial.result.concat(other.result); } return true; } public String terminate() { return new String(partial.result); } } }
上一篇: 隔壁一哥们和我关系特别好
下一篇: MySQL8.0初体验
推荐阅读
-
基于python编写的微博应用
-
python3.6.5基于kerberos认证的hive和hdfs连接调用方式
-
C#编写了一个基于Lucene.Net的搜索引擎查询通用工具类:SearchEngineUtil
-
基于Vuejs和Element的注册插件的编写方法
-
JAVA WEB快速入门之从编写一个基于SpringBoot+Mybatis快速创建的REST API项目了解SpringBoot、SpringMVC REST API、Mybatis等相关知识
-
JAVA WEB快速入门之从编写一个基于SpringMVC框架的网站了解Maven、SpringMVC、SpringJDBC
-
用Python编写一个基于终端的实现翻译的脚本
-
基于Python编写一个计算器程序,实现简单的加减乘除和取余二元运算
-
JS基于for语句编写的九九乘法表示例
-
基于three.js编写的一个项目类示例代码