All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mongodb.hadoop.pig.udf.ToBinary Maven / Gradle / Ivy

Go to download

The MongoDB Connector for Hadoop is a plugin for Hadoop that provides the ability to use MongoDB as an input source and/or an output destination.

The newest version!
package com.mongodb.hadoop.pig.udf;

import com.mongodb.hadoop.pig.udf.types.PigBoxedBinary;
import org.apache.pig.data.DataByteArray;
import org.apache.pig.data.Tuple;

import java.io.IOException;

/**
 * Pig UDF that transforms the incoming value into a BSON Binary object.
 */
public class ToBinary extends ByteArrayTypeEvalFunc {
    @Override
    public PigBoxedBinary exec(final Tuple input) throws IOException {
        if (null == input || input.size() == 0) {
            return null;
        }
        Object o = input.get(0);
        if (o instanceof String) {
            return new PigBoxedBinary(((String) o).getBytes());
        } else if (o instanceof DataByteArray) {
            return new PigBoxedBinary(((DataByteArray) o).get());
        }
        throw new IOException(
          "Need String or DataByteArray to build a Binary, not " + o);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy