Database Reference
In-Depth Information
lowercase and returns it back to the caller. If an error occurs in the try
block, the catch block returns an error message to the caller.
Next, you need to build the class and export it to a jar file. Place the jar file
in the Pig directory, and you are ready to use it in your scripts.
Another common type of function is the filter function. Filter functions are
eval functions that return a Boolean result. For example, the IsPositive
function is used here to filter out negative and zero-delay values (integers):
Register
C:\hdp\hadoop\pig-0.11.0.1.3.0.0-0380\SampleUDF.jar;
Define isPos
com.BigData.hadoop.pig.SampleUDF.isPositive;
FlightData = LOAD '/user/test/FlightPerformance.csv'
using PigStorage(',')
as
(flight_date:chararray,airline_cd:int,airport_cd:chararray,
delay:int,dep_time:int);
PosDelay = Filter FlightData BY isPos(delay);
The code for the isPositive UDF is shown here:
package com.BigData.hadoop.pig.SampleUDF;
import java.io.IOException;
import org.apache.pig.FilterFunc;
import org.apache.pig.data.Tuple;
public class isPositive extends FilterFunc {
@Override
public Boolean exec(Tuple arg0) throws
IOException {
if (arg0 == null || arg0.size() != 1)
return null;
try
{
if (arg0.get(0) instanceof Integer)
{
if ((Integer)arg0.get(0)>0)
return true;
else
Search WWH ::




Custom Search