October 2018
Beginner
220 pages
5h 33m
English
Pig allows users to write custom functions using User-Defined Functions (UDF) support. You can write UDF in any language, so looking at a previous example, let's try to create a filter UDF for the following expression:
filtered_records = FILTER records BY year == 2018 AND(grade matches 'A*');
Remember that when you create a filter UDF, you need to extend the FilterFunc class. The code for this custom function can be written as follows:
public class CurrentYearMatch extends FilterFunc { @Override public Boolean exec(Tuple Ftuple) throws IOException { if (tuple == null || tuple.size() == 0) { return false; } try { Object object = tuple.get(0); if (object == null) { return false; } int currentYear = (Integer) ...Read now
Unlock full access