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; }
/** * Process field of a record type. * * @param fieldDefinition schema for field. * @return generated value for field based on its definition. * @throws ConfigurationGenerationException configuration processing exception */ private Object processField(Field fieldDefinition) throws ConfigurationGenerationException { // if this a "uuid" type then generate it if (UUID_FIELD.equals(fieldDefinition.name())) { return AvroUtils.generateUuidObject(); } return processType(fieldDefinition.schema(), fieldDefinition.getJsonProp(BY_DEFAULT_FIELD)); }
if (fieldIter.getJsonProp(OPTIONAL_NAME) != null) { optional = fieldIter.getJsonProp(OPTIONAL_NAME).asBoolean();
public static Map<Integer, FieldMapping> parseKeyMappingsFromSchemaFields( Schema schema) { Map<Integer, FieldMapping> keyMappings = Maps.newHashMap(); if (Schema.Type.RECORD == schema.getType()) { for (Schema.Field field : schema.getFields()) { if (field.getJsonProp(MAPPING) != null) { // parse the String because Avro uses com.codehaus.jackson JsonNode mappingNode = JsonUtil.parse( field.getJsonProp(MAPPING).toString()); FieldMapping fm = parseFieldMapping(field.name(), mappingNode); if (FieldMapping.MappingType.KEY == fm.getMappingType() && mappingNode.has(VALUE)) { Integer index = mappingNode.get(VALUE).asInt(); keyMappings.put(index, fm); } } } return keyMappings; } throw new IllegalArgumentException( "Cannot parse field-level mappings from non-Record"); }
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; }
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; }
public static ColumnMapping parseFromSchemaFields(Schema schema) { if (Schema.Type.RECORD == schema.getType()) { ColumnMapping.Builder builder = new ColumnMapping.Builder(); for (Schema.Field field : schema.getFields()) { if (field.getJsonProp(MAPPING) != null) { // parse the String because Avro uses com.codehaus.jackson builder.fieldMapping(parseFieldMapping(field.name(), JsonUtil.parse(field.getJsonProp(MAPPING).toString()))); } } return builder.build(); } throw new IllegalArgumentException( "Cannot parse field-level mappings from non-Record"); }
@Override public JsonNode getJsonProp(final String name) { return wrapped.getJsonProp(name); }
public static boolean hasEmbeddedFieldMappings(Schema schema) { if (Schema.Type.RECORD == schema.getType()) { for (Schema.Field field : schema.getFields()) { if (field.getJsonProp(MAPPING) != null) { return true; } } } return false; }
@Override protected void customizeFormField(Record fieldType, Field field) { if (fieldType.getSchema().getName().equals(ARRAY_FIELD_TYPE)) { JsonNode overrideStrategyNode = field.getJsonProp(OVERRIDE_STRATEGY); Schema overrideStrategySchema = fieldType.getSchema().getField(OVERRIDE_STRATEGY).schema(); if (overrideStrategyNode != null && overrideStrategyNode.isTextual()) { fieldType.put(OVERRIDE_STRATEGY, new GenericData.EnumSymbol( overrideStrategySchema, overrideStrategyNode.asText().toUpperCase())); } else { fieldType.put(OVERRIDE_STRATEGY, new GenericData.EnumSymbol( overrideStrategySchema, OverrideStrategy.REPLACE.name())); } } }