AvroUtils { public static Map<String, Object> extractProperties(Schema schema, String propName) { final Map<String, Object> props = new HashMap<>(); if (schema != null && StringUtils.isNoneEmpty(propName)) { extractProperties(schema, propName, props, ""); } return props; }  static Schema createRecordSemanticSchema(Schema sourceSchema, Schema valueLevelMetadataSchema); static Schema copySchema(Schema sourceSchema); static boolean isPrimitiveType(Schema.Type type); static boolean isPrimitiveType(Schema.Type type, boolean enumFixedIncluded); static String itemId(String prefix, String itemId); static Map<String, Object> extractProperties(Schema schema, String propName); static void extractProperties(Schema schema, String propName, Map<String, Object> props, String prefix); static Pair<Stream<IndexedRecord>, Schema> streamAvroFile(File file); static Schema dereferencing(Schema schema); static Schema cleanSchema(Schema schema, List<String> propsToAvoid);  }
@Test public void testExtractNull() { Map<String, Object> props = AvroUtils.extractProperties(null, ""); assertTrue(props.size() == 0); props = AvroUtils.extractProperties(Schema.create(Schema.Type.STRING), ""); assertTrue(props.size() == 0); }
@Test public void testExtractSimpleRecord() { Schema schema = createSimpleRecordSchema(); Map<String, Object> props = AvroUtils.extractProperties(schema, "quality"); assertEquals(2, props.size()); assertEquals("not so bad", props.get("firstname")); assertEquals("not so bad", props.get("lastname")); }
@Test public void testExtractComplexRecord() { Schema schema = createComplexRecordSchema(); Map<String, Object> props = AvroUtils.extractProperties(schema, "quality"); assertEquals(4, props.size()); assertEquals("not so bad", props.get("emails")); assertEquals("not so bad", props.get("location.country")); assertEquals("not so bad", props.get("age.string")); assertEquals("not so bad", props.get("age.int")); }