use of org.apache.avro.generic.GenericData.Record in project incubator-gobblin by apache.
the class AvroUtils method decorateRecord.
/**
* Decorate a {@link GenericRecord} with additional fields and make it conform to an extended Schema
* It is the caller's responsibility to ensure that the outputSchema is the merge of the inputRecord's schema
* and the additional fields. The method does not check this for performance reasons, because it is expected to be called in the
* critical path of processing a record.
* Use {@link AvroUtils#decorateRecordSchema(Schema, List)} to generate such a Schema before calling this method.
* @param inputRecord: record with data to be copied into the output record
* @param fieldMap: values can be primitive types or GenericRecords if nested
* @param outputSchema: the schema that the decoratedRecord will conform to
* @return an outputRecord that contains a union of the fields in the inputRecord and the field-values in the fieldMap
*/
public static GenericRecord decorateRecord(GenericRecord inputRecord, @Nonnull Map<String, Object> fieldMap, Schema outputSchema) {
GenericRecord outputRecord = new GenericData.Record(outputSchema);
inputRecord.getSchema().getFields().forEach(f -> outputRecord.put(f.name(), inputRecord.get(f.name())));
fieldMap.forEach((key, value) -> outputRecord.put(key, value));
return outputRecord;
}
Aggregations