pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Pig Wiki] Update of "FilterFunction" by OlgaN
Date Wed, 07 Nov 2007 19:02:08 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Pig Wiki" for change notification.

The following page has been changed by OlgaN:

New page:
== Filter Functions ==

Filter functions are like Eval functions except that they can only return true or false. Hence
these functions may be used in a FILTER statement to eliminate unwanted tuples from a relation
or bag.

To create your own Filter Function, create a Java class that extends the following abstract

public abstract class FilterFunc {    
    abstract public boolean exec(Tuple input) throws IOException;

Input to the function is passed exactly as for EvalFunction. 

=== Example ===

Our built-in !IsEmpty() function tests whether a bag is empty. The code is:

public class IsEmpty extends FilterFunc {

    public boolean exec(Tuple input) throws IOException {
        return (input.getBagField(0).cardinality() == 0);


=== Advanced Features ===
   * As in EvalFunction, any final cleanup action can be performed by overriding the finish

View raw message