* @return The AvroFieldMapping of this field.
*/
private FieldMapping createFieldMapping(String fieldName,
JsonNode recordFieldJson, Map<String, Object> defaultValueMap,
Schema.Type type) {
FieldMapping fieldMapping = null;
JsonNode mappingNode = recordFieldJson.get("mapping");
if (mappingNode != null) {
JsonNode mappingTypeNode = mappingNode.get("type");
JsonNode mappingValueNode = mappingNode.get("value");
JsonNode prefixValueNode = mappingNode.get("prefix");
if (mappingTypeNode == null) {
String msg = "mapping attribute must contain type.";
throw new SchemaValidationException(msg);
}
MappingType mappingType = null;
String mappingValue = null;
String prefix = null;
if (mappingTypeNode.getTextValue().equals("column")) {
mappingType = MappingType.COLUMN;
if (mappingValueNode == null) {
throw new SchemaValidationException(
"column mapping type must contain a value.");
}
mappingValue = mappingValueNode.getTextValue();
} else if ((mappingTypeNode.getTextValue().equals("keyAsColumn"))) {
mappingType = MappingType.KEY_AS_COLUMN;
if (mappingValueNode == null) {
throw new SchemaValidationException(
"keyAsColumn mapping type must contain a value.");
}
mappingValue = mappingValueNode.getTextValue();
if (prefixValueNode != null) {
prefix = prefixValueNode.getTextValue();
}
} else if (mappingTypeNode.getTextValue().equals("counter")) {
if (type != Schema.Type.INT && type != Schema.Type.LONG) {
throw new SchemaValidationException("counter mapping type must be an int or a long");
}
if (mappingValueNode == null) {
throw new SchemaValidationException(
"counter mapping type must contain a value.");
}
mappingType = MappingType.COUNTER;
mappingValue = mappingValueNode.getTextValue();
} else if (mappingTypeNode.getTextValue().equals("occVersion")) {
mappingType = MappingType.OCC_VERSION;
} else if (mappingTypeNode.getTextValue().equals("key")) {
mappingType = MappingType.KEY;
if (mappingValueNode == null) {
throw new SchemaValidationException(
"key mapping type must contain an integer value specifying it's key order.");
}
mappingValue = mappingValueNode.getTextValue();
}
Object defaultValue = defaultValueMap.get(fieldName);
fieldMapping = new FieldMapping(fieldName, mappingType, mappingValue,
defaultValue, prefix);
}
return fieldMapping;
}