Search in sources :

Example 1 with ThriftBytesToTuple

use of com.twitter.elephantbird.pig.piggybank.ThriftBytesToTuple in project elephant-bird by twitter.

the class TestThriftToPig method bytesToTuple.

static <M extends TBase<?, ?>> Tuple bytesToTuple(M obj) throws TException, ExecException, IOException {
    // test ThriftBytesToTuple UDF.
    // first serialize obj and then invoke the UDF.
    TypeRef<M> typeRef = new TypeRef<M>(obj.getClass()) {
    };
    ThriftConverter<M> converter = ThriftConverter.newInstance(typeRef);
    ThriftBytesToTuple<M> tTuple = new ThriftBytesToTuple<M>(obj.getClass().getName());
    Tuple tuple = tupleFactory.newTuple(1);
    tuple.set(0, new DataByteArray(converter.toBytes(obj)));
    return tTuple.exec(tuple);
}
Also used : TypeRef(com.twitter.elephantbird.util.TypeRef) ThriftBytesToTuple(com.twitter.elephantbird.pig.piggybank.ThriftBytesToTuple) DataByteArray(org.apache.pig.data.DataByteArray) ThriftBytesToTuple(com.twitter.elephantbird.pig.piggybank.ThriftBytesToTuple) Tuple(org.apache.pig.data.Tuple)

Aggregations

ThriftBytesToTuple (com.twitter.elephantbird.pig.piggybank.ThriftBytesToTuple)1 TypeRef (com.twitter.elephantbird.util.TypeRef)1 DataByteArray (org.apache.pig.data.DataByteArray)1 Tuple (org.apache.pig.data.Tuple)1