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++;
}
}
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;
}
}
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());
}
Aggregations