use of org.apache.pig.LoadPushDown.RequiredField in project elephant-bird by twitter.
the class TestProtoToPig method evenFields.
private static RequiredFieldList evenFields(List<FieldDescriptor> protoFields) {
RequiredFieldList reqList = new RequiredFieldList();
int i = 0;
for (FieldDescriptor fd : protoFields) {
if (i % 2 == 0) {
RequiredField field = new RequiredField();
field.setAlias(fd.getName());
field.setIndex(i);
// field.setType() type is not used
reqList.add(field);
}
i++;
}
return reqList;
}
use of org.apache.pig.LoadPushDown.RequiredField in project elephant-bird by twitter.
the class TestThriftToPig method thriftToPig.
static <M extends TBase<?, ?>> Tuple thriftToPig(M obj) throws TException {
// it is very inefficient to create one ThriftToPig for each Thrift object,
// but good enough for unit testing.
TypeRef<M> typeRef = new TypeRef<M>(obj.getClass()) {
};
ThriftToPig<M> thriftToPig = ThriftToPig.newInstance(typeRef);
Tuple t = thriftToPig.getPigTuple(obj);
// test projected tuple. project a subset of fields based on field name.
List<Field> tFields = thriftToPig.getTStructDescriptor().getFields();
List<Integer> idxList = Lists.newArrayList();
RequiredFieldList reqFieldList = new RequiredFieldList();
for (int i = 0; i < tFields.size(); i++) {
String name = tFields.get(i).getName();
if (name.hashCode() % 2 == 0) {
RequiredField rf = new RequiredField();
rf.setAlias(name);
rf.setIndex(i);
reqFieldList.add(rf);
idxList.add(i);
}
}
try {
Tuple pt = new ProjectedThriftTupleFactory<M>(typeRef, reqFieldList).newTuple(obj);
int pidx = 0;
for (int idx : idxList) {
if (t.get(idx) != pt.get(pidx)) {
// if both are not nulls
assertEquals(t.get(idx).toString(), pt.get(pidx).toString());
}
pidx++;
}
} catch (ExecException e) {
// not expected
throw new TException(e);
}
// return the full tuple
return t;
}
Aggregations