Search in sources :

Example 1 with ProtobufTuple

use of com.twitter.elephantbird.pig.util.ProtobufTuple in project elephant-bird by twitter.

the class TestProtoToPig method testLazyProtoToPig.

@Test
public void testLazyProtoToPig() throws ExecException {
    Person personProto = Fixtures.buildPersonProto();
    Tuple protoTuple = new ProtobufTuple(personProto);
    Tuple normalTuple = Fixtures.buildPersonTuple();
    List<FieldDescriptor> fieldDescs = personProto.getDescriptorForType().getFields();
    TypeRef<Person> typeRef = PigUtil.getProtobufTypeRef(Person.class.getName());
    Tuple projectedTuple = new ProjectedProtobufTupleFactory<Person>(typeRef, evenFields(fieldDescs)).newTuple(personProto);
    int idx = 0;
    for (FieldDescriptor fd : fieldDescs) {
        // gives us non-null fields, which are not equal to the null fields...
        if (normalTuple.get(fd.getIndex()) instanceof DataBag) {
            continue;
        }
        assertEquals(protoTuple.get(fd.getIndex()), normalTuple.get(fd.getIndex()));
        if (idx % 2 == 0) {
            assertEquals(projectedTuple.get(fd.getIndex() / 2), normalTuple.get(fd.getIndex()));
        }
        idx++;
    }
}
Also used : DataBag(org.apache.pig.data.DataBag) ProtobufTuple(com.twitter.elephantbird.pig.util.ProtobufTuple) Person(com.twitter.data.proto.tutorial.AddressBookProtos.Person) ProtobufTuple(com.twitter.elephantbird.pig.util.ProtobufTuple) Tuple(org.apache.pig.data.Tuple) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) Test(org.junit.Test)

Example 2 with ProtobufTuple

use of com.twitter.elephantbird.pig.util.ProtobufTuple in project elephant-bird by twitter.

the class ProtobufBytesToTuple method exec.

@Override
public Tuple exec(Tuple input) throws IOException {
    if (input == null || input.size() < 1) {
        return null;
    }
    try {
        DataByteArray bytes = (DataByteArray) input.get(0);
        M value_ = protoConverter_.fromBytes(bytes.get());
        return new ProtobufTuple(value_);
    } catch (IOException e) {
        return null;
    }
}
Also used : ProtobufTuple(com.twitter.elephantbird.pig.util.ProtobufTuple) IOException(java.io.IOException) DataByteArray(org.apache.pig.data.DataByteArray)

Example 3 with ProtobufTuple

use of com.twitter.elephantbird.pig.util.ProtobufTuple in project elephant-bird by twitter.

the class TimeProtoConversions method main.

/**
 * @param args
 * @throws ExecException
 */
public static void main(String[] args) throws ExecException {
    int iterations = 100000;
    ProtobufToPig protoConv = new ProtobufToPig();
    for (int i = 0; i < iterations; i++) {
        Person proto = Fixtures.buildPersonProto();
        Tuple t = protoConv.toTuple(proto);
        t.get(0);
        t = new ProtobufTuple(proto);
        t.get(0);
    }
    StopWatch timer = new StopWatch();
    timer.start();
    for (int i = 0; i < iterations; i++) {
        Person proto = Fixtures.buildPersonProto();
        Tuple t = protoConv.toTuple(proto);
        t.get(0);
    }
    timer.split();
    System.err.println(timer.getSplitTime());
    timer.reset();
    timer.start();
    for (int i = 0; i < iterations; i++) {
        Person proto = Fixtures.buildPersonProto();
        Tuple t = new ProtobufTuple(proto);
        t.get(0);
    }
    timer.split();
    System.err.println(timer.getSplitTime());
}
Also used : ProtobufToPig(com.twitter.elephantbird.pig.util.ProtobufToPig) ProtobufTuple(com.twitter.elephantbird.pig.util.ProtobufTuple) Person(com.twitter.data.proto.tutorial.AddressBookProtos.Person) ProtobufTuple(com.twitter.elephantbird.pig.util.ProtobufTuple) Tuple(org.apache.pig.data.Tuple) StopWatch(org.apache.commons.lang.time.StopWatch)

Aggregations

ProtobufTuple (com.twitter.elephantbird.pig.util.ProtobufTuple)3 Person (com.twitter.data.proto.tutorial.AddressBookProtos.Person)2 Tuple (org.apache.pig.data.Tuple)2 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)1 ProtobufToPig (com.twitter.elephantbird.pig.util.ProtobufToPig)1 IOException (java.io.IOException)1 StopWatch (org.apache.commons.lang.time.StopWatch)1 DataBag (org.apache.pig.data.DataBag)1 DataByteArray (org.apache.pig.data.DataByteArray)1 Test (org.junit.Test)1