LongWritable key = new LongWritable(1);
Schema pairSchema = DBMapper.getPairSchema(val.getColumns());
Schema keySchema = Pair.getKeySchema(pairSchema);
Schema valueSchema = Pair.getValueSchema(pairSchema);
Pair pair = new Pair<GenericRecord, GenericRecord>(pairSchema);
GenericRecord keyRecord = new GenericData.Record(keySchema);
keyRecord.put(0, key.get());
GenericRecord valueRecord = new GenericData.Record(valueSchema);
List<Schema.Field> fieldSchemas = valueSchema.getFields();
for (int i = 0; i < val.getValues().size(); ++i) {
Schema.Type type = fieldSchemas.get(i).schema().getType();
if (type.equals(Schema.Type.STRING)) {
Utf8 utf8 = new Utf8((String) val.getValues().get(i).toString());
valueRecord.put(i, utf8);
} else {
valueRecord.put(i, val.getValues().get(i));
}
}
pair.key(keyRecord);
pair.value(valueRecord);
mapper.map(key, val, output, reporter);
verify(output).collect(new AvroValue<Pair>(pair), nullWritable);
}