CollapserUtils { public static <T extends IndexedRecord> T merge(T base, T update) { T ret = GenericData.get().deepCopy(base.getSchema(), base); for (Field field: base.getSchema().getFields()) { if (base.get(field.pos()) == null && update.get(field.pos()) != null) { ret.put(field.pos(), update.get(field.pos())); } } return ret; } private  CollapserUtils(); static boolean haveEqualSchema(Collection<IndexedRecord> records); static boolean isEnvelopeSchema(Schema schema); static String getOriginValue(IndexedRecord record); static IndexedRecord getDataRecord(IndexedRecord record); @SuppressWarnings("unchecked") static T getNestedFieldValue(IndexedRecord record, String fieldName); static int getNumberOfFilledFields(IndexedRecord record, List<String> fields); static void sortByFilledDataFields(List<T> records, final List<String> fields); static T merge(T base, T update);  }
@Test public void testMerge() { SampleData.assertEqualRecords( SampleData.mergedRecord1112, CollapserUtils.merge(SampleData.metadataRecord11, SampleData.metadataRecord12)); SampleData.assertEqualRecords( SampleData.mergedRecord2221, CollapserUtils.merge(SampleData.metadataRecord22, SampleData.metadataRecord21)); }