Object fieldValue = null;
switch (fieldSchema.getType()) {
case MAP:
case ARRAY:
case RECORD:
@SuppressWarnings("rawtypes")
SpecificDatumReader reader = getDatumReader(fieldSchema.getFullName(),
fieldSchema);
fieldValue = IOUtils.deserialize((byte[]) solrValue, reader, fieldSchema,
persistent.get(field.pos()));
break;
case ENUM:
fieldValue = AvroUtils.getEnumValue(fieldSchema, (String) solrValue);
break;
case FIXED:
throw new IOException("???");
// break;
case BYTES:
fieldValue = ByteBuffer.wrap((byte[]) solrValue);
break;
case STRING:
fieldValue = new Utf8(solrValue.toString());
break;
case UNION:
if (fieldSchema.getTypes().size() == 2 && isNullable(fieldSchema)) {
// schema [type0, type1]
Type type0 = fieldSchema.getTypes().get(0).getType();
Type type1 = fieldSchema.getTypes().get(1).getType();
// Check if types are different and there's a "null", like
// ["null","type"] or ["type","null"]
if (!type0.equals(type1)) {
if (type0.equals(Schema.Type.NULL))
fieldSchema = fieldSchema.getTypes().get(1);
else
fieldSchema = fieldSchema.getTypes().get(0);
} else {
fieldSchema = fieldSchema.getTypes().get(0);
}
fieldValue = deserializeFieldValue(field, fieldSchema, solrValue,
persistent);
} else {
@SuppressWarnings("rawtypes")
SpecificDatumReader unionReader = getDatumReader(
String.valueOf(fieldSchema.hashCode()), fieldSchema);
fieldValue = IOUtils.deserialize((byte[]) solrValue, unionReader,
fieldSchema, persistent.get(field.pos()));
break;