* @return the list of fields
* @throws SerDeException
* @throws MetaException
*/
public static List<FieldSchema> getFieldsFromDeserializer(String tableName, Deserializer deserializer) throws SerDeException, MetaException {
ObjectInspector oi = deserializer.getObjectInspector();
String [] names = tableName.split("\\.");
String last_name = names[names.length-1];
for(int i = 1; i < names.length; i++) {
if (oi instanceof StructObjectInspector) {
StructObjectInspector soi = (StructObjectInspector)oi;
StructField sf = soi.getStructFieldRef(names[i]);
if (sf == null) {
throw new MetaException("Invalid Field " + names[i]);
} else {
oi = sf.getFieldObjectInspector();
}
}
else if (oi instanceof ListObjectInspector && names[i].equalsIgnoreCase("$elem$")) {
ListObjectInspector loi = (ListObjectInspector)oi;
oi = loi.getListElementObjectInspector();
}
else if (oi instanceof MapObjectInspector && names[i].equalsIgnoreCase("$key$")) {
MapObjectInspector moi = (MapObjectInspector)oi;
oi = moi.getMapKeyObjectInspector();
}
else if (oi instanceof MapObjectInspector && names[i].equalsIgnoreCase("$value$")) {
MapObjectInspector moi = (MapObjectInspector)oi;
oi = moi.getMapValueObjectInspector();
}
else {
throw new MetaException("Unknown type for " + names[i]);
}
}
ArrayList<FieldSchema> str_fields = new ArrayList<FieldSchema>();
// rules on how to recurse the ObjectInspector based on its type
if (oi.getCategory() != Category.STRUCT) {
str_fields.add(new FieldSchema(last_name, oi.getTypeName(), "from deserializer"));
} else {
List<? extends StructField> fields = ((StructObjectInspector)oi).getAllStructFieldRefs();
for(int i=0; i<fields.size(); i++) {
String fieldName = fields.get(i).getFieldName();
String fieldTypeName = fields.get(i).getFieldObjectInspector().getTypeName();