List<Schema.Field> outFields = new ArrayList<Schema.Field>();
for (int i = 0; i < pigFields.length; i++) {
/* get user defined avro field schema */
Field inputField = isPartialSchema ? AvroStorageUtils.getUDField(avroSchema, i) : inFields.get(i);
/* get schema */
Schema fieldSchema = null;
if (inputField == null) {
/* convert pig schema (nullable) */
fieldSchema = convert(pigFields[i], true);
} else if (inputField.schema() == null) {
/* convert pig schema (not-null) */
fieldSchema = convert(pigFields[i], false);
} else {
/* validate pigFields[i] with given avro schema */
fieldSchema = validateAndConvert(inputField.schema(),
pigFields[i]);
}
/* get field name of output */
String outname = (isPartialSchema) ? pigFields[i].getName() : inputField.name();
if (outname == null)
outname = FIELD_NAME + "_" + i; // field name cannot be null
/* get doc of output */
String doc = (isPartialSchema) ? pigFields[i].getDescription() : inputField.doc();
outFields.add(new Field(outname, fieldSchema, doc, null));
}
outSchema.setFields(outFields);
return outSchema;