hive UDAF
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章