datafu.pig.util
Class AssertUDF
java.lang.Object
org.apache.pig.EvalFunc<java.lang.Boolean>
org.apache.pig.FilterFunc
datafu.pig.util.AssertUDF
- Direct Known Subclasses:
- Assert
public class AssertUDF
- extends org.apache.pig.FilterFunc
Filter function which asserts that a value is true.
Unfortunately, the Pig interpreter doesn't recognize boolean expressions nested as function
arguments, so this uses C-style booleans. That is, the first argument should be
an integer. 0 is interpreted as "false", and anything else is considered "true".
The function will cause the Pig script to fail if a "false" value is encountered.
There is a unary and a binary version. The unary version just takes a boolean, and throws out a generic exception message when the
assertion is violated. The binary version takes a String as a second argument and throws that out when the assertion
is violated.
Example:
FILTER members BY AssertUDF( (member_id >= 0 ? 1 : 0), 'Doh! Some member ID is negative.' );
Fields inherited from class org.apache.pig.EvalFunc |
log, pigLogger, reporter, returnType |
Method Summary |
java.lang.Boolean |
exec(org.apache.pig.data.Tuple tuple)
|
Methods inherited from class org.apache.pig.FilterFunc |
finish |
Methods inherited from class org.apache.pig.EvalFunc |
getArgToFuncMapping, getCacheFiles, getInputSchema, getLogger, getPigLogger, getReporter, getReturnType, getSchemaName, isAsynchronous, outputSchema, progress, setInputSchema, setPigLogger, setReporter, setUDFContextSignature, warn |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
AssertUDF
public AssertUDF()
exec
public java.lang.Boolean exec(org.apache.pig.data.Tuple tuple)
throws java.io.IOException
- Specified by:
exec
in class org.apache.pig.EvalFunc<java.lang.Boolean>
- Throws:
java.io.IOException
Matthew Hayes, Sam Shah