public RequiredFieldResponse fieldsToRead(RequiredFieldList requiredFieldList) throws FrontendException {
String pigLoadSignature = requiredFieldList.getSignature();
if(pigLoadSignature == null) {
throw new FrontendException("Zebra Cannot have null loader signature in fieldsToRead");
}
List<RequiredField> rFields = requiredFieldList.getFields();
if( rFields == null) {
throw new FrontendException("requiredFieldList.getFields() can not return null in fieldsToRead");
}
Iterator<RequiredField> it= rFields.iterator();
String projectionStr = "";
while( it.hasNext()) {
RequiredField rField = (RequiredField) it.next();
ColumnSchema cs = projectionSchema.getColumn(rField.getIndex());
if(cs == null) {
throw new FrontendException
("Null column schema in projection schema in fieldsToRead at index " + rField.getIndex());
}
if(cs.getType() != ColumnType.MAP && (rField.getSubFields() != null)) {
throw new FrontendException
("Zebra cannot have subfields for a non-map column type in fieldsToRead " +
"ColumnType:" + cs.getType() + " index in zebra projection schema: " + rField.getIndex()
);
}
String name = cs.getName();
projectionStr = projectionStr + name ;
if(cs.getType() == ColumnType.MAP) {
List<RequiredField> subFields = rField.getSubFields();
if( subFields != null ) {
Iterator<RequiredField> its= subFields.iterator();
boolean flag = false;
if(its.hasNext()) {
flag = true;
projectionStr += "#" + "{";
}
String tmp = "";
while(its.hasNext()) {
RequiredField sField = (RequiredField) its.next();
tmp = tmp + sField.getAlias();
if(its.hasNext()) {
tmp = tmp + "|";
}
}
if ( flag) {
projectionStr = projectionStr + tmp + "}";
}
}
}
if(it.hasNext()) {
projectionStr = projectionStr + " , ";
}
}
Properties p = UDFContext.getUDFContext().getUDFProperties(this.getClass());
if(p == null) {
throw new FrontendException("Zebra Cannot have null UDFCOntext property");
}
if(projectionStr != null && (projectionStr != ""))
p.setProperty(pigLoadSignature, projectionStr);