Class AssertUDF

  extended by org.apache.pig.EvalFunc<java.lang.Boolean>
      extended by org.apache.pig.FilterFunc
          extended by datafu.pig.util.AssertUDF
Direct Known Subclasses:

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.


 FILTER members BY AssertUDF( (member_id >= 0 ? 1 : 0), 'Doh! Some member ID is negative.' );

Field Summary
Fields inherited from class org.apache.pig.EvalFunc
log, pigLogger, reporter, returnType
Constructor Summary
Method Summary
 java.lang.Boolean exec( tuple)
Methods inherited from class org.apache.pig.FilterFunc
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

Constructor Detail


public AssertUDF()
Method Detail


public java.lang.Boolean exec( tuple)
Specified by:
exec in class org.apache.pig.EvalFunc<java.lang.Boolean>

Matthew Hayes, Sam Shah