for (int i = 1; i < fields.size(); i++) {
if (!val.isDirty(i)) {
continue;
}
Field field = fields.get(i);
Object o = val.get(field.pos());
Pair<Text,Text> col = mapping.fieldMap.get(field.name());
if (col == null) {
throw new GoraException("Please define the gora to accumulo mapping for field " + field.name());
}
switch (field.schema().getType()) {
case MAP:
count = putMap(m, count, field.schema().getValueType(), o, col);
break;
case ARRAY:
count = putArray(m, count, o, col);
break;
case UNION: // default value of null acts like union with null
Schema effectiveSchema = field.schema().getTypes()
.get(firstNotNullSchemaTypeIndex(field.schema()));
// map and array need to compute qualifier
if (effectiveSchema.getType() == Type.ARRAY) {
count = putArray(m, count, o, col);
break;
}
else if (effectiveSchema.getType() == Type.MAP) {
count = putMap(m, count, effectiveSchema.getValueType(), o, col);
break;
}
// continue like a regular top-level union
case RECORD:
SpecificDatumWriter<Object> writer = new SpecificDatumWriter<Object>(field.schema());
ByteArrayOutputStream os = new ByteArrayOutputStream();
org.apache.avro.io.BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(os, null);
writer.write(o, encoder);
encoder.flush();
m.put(col.getFirst(), col.getSecond(), new Value(os.toByteArray()));