Database Reference
In-Depth Information
package Com.BigData.hadoop.hive.SampleUDF;
import org.apache.hadoop.hive.ql.exec.UDF;
public class OrderNums extends UDF{
}
The next step is to add an evaluate function that will do the processing and
return the results. The following code processes the two integers passed in
and returns the larger value. If they are equal it returns null. Because you
are using the IntWritable class, you need to add an import for pointing
to the org,apache.hadoop.io.IntWritable class in the
Hadoop-core.jar file:
package Com.BigData.hadoop.hive.SampleUDF;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.hive.ql.exec.UDF;
public class GetMaxInt extends UDF{
public IntWritable evaluate(IntWritable x,
IntWritable y)
{
if (x.get()>y.get())
return x;
else if (x.get()<y.get())
return y;
else
return null;
}
}
After creating and compiling the code into a jar file, deploy it to the hive
directory. Once deployed youadd thefile tothehive class path and create an
alias for the function using the Hive command line:
add jar
C:\hdp\hadoop\hive-0.11.0.1.3.0.0-0380\lib\SampleUDF.jar;
create temporary function GetMaxInt as
'Com.BigData.hadoop.hive.SampleUDF.GetMaxInt';
You can now call the UDF in your HiveQL. Pass in two integers to get the
larger value:
Search WWH ::




Custom Search