mirror of https://github.com/apache/nifi.git
NIFI-5678: Fixed MAP type support of MapRecord objects in StandardSchemaValidator
This closes #3060. Signed-off-by: Mark Payne <markap14@hotmail.com>
This commit is contained in:
parent
f55204cb69
commit
218063a0b5
|
@ -196,21 +196,32 @@ public class StandardSchemaValidator implements RecordSchemaValidator {
|
|||
|
||||
return true;
|
||||
case MAP:
|
||||
if (!(value instanceof Map)) {
|
||||
if (value instanceof Map) {
|
||||
final MapDataType mapDataType = (MapDataType) dataType;
|
||||
final DataType valueDataType = mapDataType.getValueType();
|
||||
final Map<?, ?> map = (Map<?, ?>) value;
|
||||
|
||||
for (final Object mapValue : map.values()) {
|
||||
if (!isTypeCorrect(mapValue, valueDataType)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if (value instanceof Record) {
|
||||
Record record = (Record) value;
|
||||
final MapDataType mapDataType = (MapDataType) dataType;
|
||||
final DataType valueDataType = mapDataType.getValueType();
|
||||
|
||||
for (final String fieldName : record.getRawFieldNames()) {
|
||||
final Object fieldValue = record.getValue(fieldName);
|
||||
if (!isTypeCorrect(fieldValue, valueDataType)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
final MapDataType mapDataType = (MapDataType) dataType;
|
||||
final DataType valueDataType = mapDataType.getValueType();
|
||||
final Map<?, ?> map = (Map<?, ?>) value;
|
||||
|
||||
for (final Object mapValue : map.values()) {
|
||||
if (!isTypeCorrect(mapValue, valueDataType)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
case RECORD:
|
||||
return value instanceof Record;
|
||||
case CHOICE:
|
||||
|
|
|
@ -75,6 +75,13 @@ public class TestStandardSchemaValidator {
|
|||
intMap.put("height", 48);
|
||||
intMap.put("width", 96);
|
||||
|
||||
List<RecordField> mapRecordFields = new ArrayList<>();
|
||||
RecordField mapRecordField = new RecordField("mapRecord", RecordFieldType.MAP.getMapDataType(RecordFieldType.INT.getDataType()));
|
||||
mapRecordFields.add(mapRecordField);
|
||||
fields.add(mapRecordField);
|
||||
RecordSchema mapRecordSchema = new SimpleRecordSchema(mapRecordFields);
|
||||
MapRecord mapRecord = new MapRecord(mapRecordSchema, intMap);
|
||||
|
||||
final RecordSchema schema = new SimpleRecordSchema(fields);
|
||||
final Map<String, Object> valueMap = new LinkedHashMap<>();
|
||||
valueMap.put("string", "string");
|
||||
|
@ -94,6 +101,7 @@ public class TestStandardSchemaValidator {
|
|||
valueMap.put("array", null);
|
||||
valueMap.put("choice", 48L);
|
||||
valueMap.put("map", intMap);
|
||||
valueMap.put("mapRecord", mapRecord);
|
||||
|
||||
final Record record = new MapRecord(schema, valueMap);
|
||||
|
||||
|
|
Loading…
Reference in New Issue