@Test public void testGetDeltaFieldNamesForNewSchema(){ Configuration conf = mock(Configuration.class); when(conf.get(FieldAttributeBasedDeltaFieldsProvider.ATTRIBUTE_FIELD)).thenReturn("attributes_json"); when(conf.get(FieldAttributeBasedDeltaFieldsProvider.DELTA_PROP_NAME, FieldAttributeBasedDeltaFieldsProvider.DEFAULT_DELTA_PROP_NAME)) .thenReturn(FieldAttributeBasedDeltaFieldsProvider.DEFAULT_DELTA_PROP_NAME); AvroDeltaFieldNameProvider provider = new FieldAttributeBasedDeltaFieldsProvider(conf); Schema original = new Schema.Parser().parse(FULL_SCHEMA_WITH_ATTRIBUTES); GenericRecord record = mock(GenericRecord.class); when(record.getSchema()).thenReturn(original); List<String> fields = provider.getDeltaFieldNames(record); Assert.assertEquals(fields, Lists.newArrayList("scn2", "scn")); }
private List<String> getDeltaFieldNamesForNewSchema(Schema originalSchema) { List<String> deltaFields = new ArrayList<>(); for (Field field : originalSchema.getFields()) { String deltaAttributeField = field.getJsonProp(this.attributeField).getValueAsText(); ObjectNode objectNode = getDeltaPropValue(deltaAttributeField); if (objectNode == null || objectNode.get(this.deltaPropName) == null) { continue; } if (Boolean.parseBoolean(objectNode.get(this.deltaPropName).toString())) { deltaFields.add(field.name()); } } log.info("Will use delta fields: " + deltaFields); return deltaFields; }
FieldAttributeBasedDeltaFieldsProvider implements AvroDeltaFieldNameProvider { private List<String> getDeltaFieldNamesForNewSchema(Schema originalSchema) { List<String> deltaFields = new ArrayList<>(); for (Field field : originalSchema.getFields()) { String deltaAttributeField = field.getJsonProp(this.attributeField).getValueAsText(); ObjectNode objectNode = getDeltaPropValue(deltaAttributeField); if (objectNode == null || objectNode.get(this.deltaPropName) == null) { continue; } if (Boolean.parseBoolean(objectNode.get(this.deltaPropName).toString())) { deltaFields.add(field.name()); } } log.info("Will use delta fields: " + deltaFields); return deltaFields; } }
FieldAttributeBasedDeltaFieldsProvider implements AvroDeltaFieldNameProvider { private List<String> getDeltaFieldNamesForNewSchema(Schema originalSchema) { List<String> deltaFields = new ArrayList<>(); for (Field field : originalSchema.getFields()) { String deltaAttributeField = field.getJsonProp(this.attributeField).getValueAsText(); ObjectNode objectNode = getDeltaPropValue(deltaAttributeField); if (objectNode == null || objectNode.get(this.deltaPropName) == null) { continue; } if (Boolean.parseBoolean(objectNode.get(this.deltaPropName).toString())) { deltaFields.add(field.name()); } } log.info("Will use delta fields: " + deltaFields); return deltaFields; } FieldAttributeBasedDeltaFieldsProvider(Configuration conf); }
FieldAttributeBasedDeltaFieldsProvider implements AvroDeltaFieldNameProvider { private List<String> getDeltaFieldNamesForNewSchema(Schema originalSchema) { List<String> deltaFields = new ArrayList<>(); for (Field field : originalSchema.getFields()) { String deltaAttributeField = field.getJsonProp(this.attributeField).getValueAsText(); ObjectNode objectNode = getDeltaPropValue(deltaAttributeField); if (objectNode == null || objectNode.get(this.deltaPropName) == null) { continue; } if (Boolean.parseBoolean(objectNode.get(this.deltaPropName).toString())) { deltaFields.add(field.name()); } } log.info("Will use delta fields: " + deltaFields); return deltaFields; } FieldAttributeBasedDeltaFieldsProvider(Configuration conf); @Override List<String> getDeltaFieldNames(GenericRecord record); }
FieldAttributeBasedDeltaFieldsProvider implements AvroDeltaFieldNameProvider { private List<String> getDeltaFieldNamesForNewSchema(Schema originalSchema) { List<String> deltaFields = new ArrayList<>(); for (Field field : originalSchema.getFields()) { String deltaAttributeField = field.getJsonProp(this.attributeField).getValueAsText(); ObjectNode objectNode = getDeltaPropValue(deltaAttributeField); if (objectNode == null || objectNode.get(this.deltaPropName) == null) { continue; } if (Boolean.parseBoolean(objectNode.get(this.deltaPropName).toString())) { deltaFields.add(field.name()); } } log.info("Will use delta fields: " + deltaFields); return deltaFields; } FieldAttributeBasedDeltaFieldsProvider(Configuration conf); @Override List<String> getDeltaFieldNames(GenericRecord record); static final String ATTRIBUTE_FIELD; static final String DELTA_PROP_NAME; static final String DEFAULT_DELTA_PROP_NAME; }