}
@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) {
// Skipping data bags. Data bags actually work; it' just our fixture is not good for this,
// since it tests "default value" functionality by leaving some elements as null, expecting
// protobuf conversion to fill the nulls in. Which is what happens. But that means converting back
// 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++;
}