You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by Apache Wiki <wi...@apache.org> on 2007/11/07 20:05:56 UTC
[Pig Wiki] Update of "GroupFunction" by OlgaN
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:
http://wiki.apache.org/pig/GroupFunction
New page:
[[Anchor(Group_Functions)]]
== Group Functions ==
A Group Function assigns tuples to group(s) (''note:'' if desired, a tuple can be assigned to multiple groups).
To create your own Group Function, create a Java class that extends the following abstract class:
{{{
public abstract class GroupFunc{
/**
* @param input the tuple to be processed.
* @return the different groups that the specified tuple belongs to.
* @throws IOException
*/
abstract public Datum[] exec(Tuple input);
}
}}}
[[Anchor(Example)]]
=== Example ===
Our built-in GFAll() function puts all tuples into a single group labeled "all". The code is:
{{{
public class GFAll extends GroupFunc {
public Datum[] exec(Tuple input) {
return new Datum[]{new DataAtom("all")};
}
}
}}}
[[Anchor(Advanced_Features)]]
=== Advanced Features ===
* As in EvalFunction, Group functions can define the schema of their output by overriding the '''outputSchema''' method.
* As in EvalFunction, Group functions can perform some final cleanup by overriding the '''finish''' method.