Skip to content

Instantly share code, notes, and snippets.

Created February 22, 2017 06:10
Show Gist options
  • Save anonymous/dba4d3f0e6e28cdc0c947aab61d8a851 to your computer and use it in GitHub Desktop.
Save anonymous/dba4d3f0e6e28cdc0c947aab61d8a851 to your computer and use it in GitHub Desktop.
import org.apache.hadoop.hive.ql.exec.UDF;
public class FindMaxDelayType extends UDF {
public enum DelayTypes {carrier,weather,nas,security,late_aircraft}
public String evaluate(double carrier, double weather, double nas, double security, double late_aircraft) {
double currentMax = carrier;
int index = 0;
if(weather > currentMax) {
currentMax = weather;
index = 1;
}
if(nas > currentMax) {
currentMax = nas;
index = 2;
}
if(security > currentMax) {
currentMax = security;
index = 3;
}
if(late_aircraft > currentMax) {
currentMax = late_aircraft;
index = 4;
}
return DelayTypes.values()[index].name();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment