首页 > 代码库 > HIVE函数UDAF 最大值

HIVE函数UDAF 最大值

Maximum 

package udf.hive.myudf;



import org.apache.hadoop.hive.ql.exec.UDAF;
import org.apache.hadoop.hive.ql.exec.UDAFEvaluator;
import org.apache.hadoop.io.IntWritable;

public class Maximum extends UDAF {

	public static class MaximumIntUDAFEvaluator implements UDAFEvaluator {
		private IntWritable result;

		public void init() {
			result = null;
		}

		public boolean iterate(IntWritable value) {
			if (value =http://www.mamicode.com/= null) {>

  

然后通过mvn打包。

add JAR /home/cloudera/Desktop/myudf-0.0.3-SNAPSHOT.jar;

 

CREATE TEMPORARY FUNCTION my_max2 AS ‘udf.hive.myudf.Maximum‘;

hive> select pid from prouct;
OK
1
2
3
4

 



select my_max2(oid) from prouct;

OK
4
Time taken: 166.32 seconds, Fetched: 1 row(s)

 

HIVE函数UDAF 最大值