Created
January 2, 2013 10:28
-
-
Save yssharma/4433633 to your computer and use it in GitHub Desktop.
Code snippet from Hadoop Guide
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 == null) { | |
| return true; | |
| } | |
| if (result == null) { | |
| result = new IntWritable(value.get()); | |
| } else { | |
| result.set(Math.max(result.get(), value.get())); | |
| } | |
| return true; | |
| } | |
| public IntWritable terminatePartial() { | |
| return result; | |
| } | |
| public boolean merge(IntWritable other) { | |
| return iterate(other); | |
| } | |
| public IntWritable terminate() { | |
| return result; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment