@Test public void testGetUnmappedFields() throws Exception { Schema input = SchemaBuilder.record("Input") .namespace("com.cloudera.edh").fields() .nullableString("s1", "").requiredString("s2") .optionalLong("l1").requiredLong("l2").endRecord(); Schema output = SchemaBuilder.record("Output") .namespace("com.cloudera.edh").fields().optionalLong("field") .endRecord(); AvroRecordConverter converter = new AvroRecordConverter(input, output, EMPTY_MAPPING); assertEquals(ImmutableList.of("field"), converter.getUnmappedFields()); converter = new AvroRecordConverter(input, output, ImmutableMap.of( "nonExistentField", "field")); assertEquals(ImmutableList.of("field"), converter.getUnmappedFields()); converter = new AvroRecordConverter(input, output, ImmutableMap.of( "parent.nonExistentField", "field")); assertEquals(ImmutableList.of("field"), converter.getUnmappedFields()); converter = new AvroRecordConverter(input, output, ImmutableMap.of( "l2", "field")); assertEquals(Collections.EMPTY_LIST, converter.getUnmappedFields()); }
public Collection<String> getUnmappedFields() { List<String> result = Lists.newArrayList(); for (Field f : outputSchema.getFields()) { String fieldName = f.name(); if (fieldMapping.containsKey(fieldName)) { fieldName = fieldMapping.get(fieldName); } Schema currentSchema = inputSchema; while (fieldName.contains(".")) { int dotIndex = fieldName.indexOf('.'); String entityName = fieldName.substring(0, dotIndex); currentSchema = getNonNullSchema(currentSchema); if (currentSchema.getField(entityName) == null) { break; } currentSchema = currentSchema.getField(entityName).schema(); fieldName = fieldName.substring(dotIndex + 1); } if (currentSchema == null || getNonNullSchema(currentSchema).getField(fieldName) == null) { result.add(f.name()); } } return result; }
AvroRecordConverter { public Collection<String> getUnmappedFields() { List<String> result = Lists.newArrayList(); for (Field f : outputSchema.getFields()) { String fieldName = f.name(); if (fieldMapping.containsKey(fieldName)) { fieldName = fieldMapping.get(fieldName); } Schema currentSchema = inputSchema; while (fieldName.contains(".")) { int dotIndex = fieldName.indexOf('.'); String entityName = fieldName.substring(0, dotIndex); currentSchema = getNonNullSchema(currentSchema); if (currentSchema.getField(entityName) == null) { break; } currentSchema = currentSchema.getField(entityName).schema(); fieldName = fieldName.substring(dotIndex + 1); } if (currentSchema == null || getNonNullSchema(currentSchema).getField(fieldName) == null) { result.add(f.name()); } } return result; } }
AvroRecordConverter { public Collection<String> getUnmappedFields() { List<String> result = Lists.newArrayList(); for (Field f : outputSchema.getFields()) { String fieldName = f.name(); if (fieldMapping.containsKey(fieldName)) { fieldName = fieldMapping.get(fieldName); } Schema currentSchema = inputSchema; while (fieldName.contains(".")) { int dotIndex = fieldName.indexOf('.'); String entityName = fieldName.substring(0, dotIndex); currentSchema = getNonNullSchema(currentSchema); if (currentSchema.getField(entityName) == null) { break; } currentSchema = currentSchema.getField(entityName).schema(); fieldName = fieldName.substring(dotIndex + 1); } if (currentSchema == null || getNonNullSchema(currentSchema).getField(fieldName) == null) { result.add(f.name()); } } return result; } AvroRecordConverter(Schema inputSchema, Schema outputSchema,
            Map<String, String> fieldMapping);  AvroRecordConverter(Schema inputSchema, Schema outputSchema,
            Map<String, String> fieldMapping, Locale locale); }
AvroRecordConverter { public Collection<String> getUnmappedFields() { List<String> result = Lists.newArrayList(); for (Field f : outputSchema.getFields()) { String fieldName = f.name(); if (fieldMapping.containsKey(fieldName)) { fieldName = fieldMapping.get(fieldName); } Schema currentSchema = inputSchema; while (fieldName.contains(".")) { int dotIndex = fieldName.indexOf('.'); String entityName = fieldName.substring(0, dotIndex); currentSchema = getNonNullSchema(currentSchema); if (currentSchema.getField(entityName) == null) { break; } currentSchema = currentSchema.getField(entityName).schema(); fieldName = fieldName.substring(dotIndex + 1); } if (currentSchema == null || getNonNullSchema(currentSchema).getField(fieldName) == null) { result.add(f.name()); } } return result; } AvroRecordConverter(Schema inputSchema, Schema outputSchema,
            Map<String, String> fieldMapping);  AvroRecordConverter(Schema inputSchema, Schema outputSchema,
            Map<String, String> fieldMapping, Locale locale); Collection<String> getUnmappedFields(); Record convert(Record input); Schema getInputSchema(); Schema getOutputSchema(); }
AvroRecordConverter { public Collection<String> getUnmappedFields() { List<String> result = Lists.newArrayList(); for (Field f : outputSchema.getFields()) { String fieldName = f.name(); if (fieldMapping.containsKey(fieldName)) { fieldName = fieldMapping.get(fieldName); } Schema currentSchema = inputSchema; while (fieldName.contains(".")) { int dotIndex = fieldName.indexOf('.'); String entityName = fieldName.substring(0, dotIndex); currentSchema = getNonNullSchema(currentSchema); if (currentSchema.getField(entityName) == null) { break; } currentSchema = currentSchema.getField(entityName).schema(); fieldName = fieldName.substring(dotIndex + 1); } if (currentSchema == null || getNonNullSchema(currentSchema).getField(fieldName) == null) { result.add(f.name()); } } return result; } AvroRecordConverter(Schema inputSchema, Schema outputSchema,
            Map<String, String> fieldMapping);  AvroRecordConverter(Schema inputSchema, Schema outputSchema,
            Map<String, String> fieldMapping, Locale locale); Collection<String> getUnmappedFields(); Record convert(Record input); Schema getInputSchema(); Schema getOutputSchema();  }