Bitwise operations in Apache Pig?

I am looking at the reference manual and cannot find documentation on bitwise operations / functions.

Is it possible to use, for example, a bitwise AND operation (equivalent to "A and B" in Hive) in a Pig script?

+4
source share
1 answer

You can provide custom UDF for this. eg. see https://pig.apache.org/docs/r0.7.0/udf.html

In a pig-breeding script you would do

REGISTER myudfs.jar;

And an example for BinaryAND UDF:

package myudfs;
import java.io.IOException;
import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;
import org.apache.pig.impl.util.WrappedIOException;

public class BitwiseAND extends EvalFunc (Integer)
{
    public String exec(Tuple input) throws IOException {
        // check input tuple:
        if (input == null || input.size() < 2)
            return null;
        try{
            return (Integer)input.get(0) & (Integer)input.get(1);
        }catch(Exception e){
            throw WrappedIOException.wrap("Caught exception processing input row ", e);
        }
    }
}

NOTE. This is not verified, it is simply copied from the udf pig page.

0
source

Source: https://habr.com/ru/post/1660792/


All Articles