values.add(new Float(1.0f));
values.add('a');
values.add(new Time(new Date().getTime()));
values.add(new Time(new Date().getTime()));
GenericDBWritable val = new GenericDBWritable(columns, values);
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);