List<FieldSchema> tableCols = table.getSd().getCols();
List<FieldSchema> newFields = new ArrayList<FieldSchema>();
for(int i = 0;i < partitionSchema.getFields().size();i++) {
FieldSchema field = HowlSchemaUtils.getFieldSchema(partitionSchema.getFields().get(i));
FieldSchema tableField;
if( i < tableCols.size() ) {
tableField = tableCols.get(i);
if( ! tableField.getName().equalsIgnoreCase(field.getName())) {
throw new HowlException(ErrorType.ERROR_SCHEMA_COLUMN_MISMATCH, "Expected column <" + tableField.getName() +
"> at position " + (i + 1) + ", found column <" + field.getName() + ">");
}
} else {
tableField = partitionKeyMap.get(field.getName().toLowerCase());
if( tableField != null ) {
throw new HowlException(ErrorType.ERROR_SCHEMA_PARTITION_KEY, "Key <" + field.getName() + ">");
}
}
if( tableField == null ) {
//field present in partition but not in table
newFields.add(field);
} else {
//field present in both. validate type has not changed
TypeInfo partitionType = TypeInfoUtils.getTypeInfoFromTypeString(field.getType());
TypeInfo tableType = TypeInfoUtils.getTypeInfoFromTypeString(tableField.getType());
if( ! partitionType.equals(tableType) ) {
throw new HowlException(ErrorType.ERROR_SCHEMA_TYPE_MISMATCH, "Column <" + field.getName() + ">, expected <" +
tableType.getTypeName() + ">, got <" + partitionType.getTypeName() + ">");
}