mirror of https://github.com/apache/nifi.git
NIFI-10106 Avoid NPE in LookupRecord.createLookupCoordinates (#6111)
This commit is contained in:
parent
5febd47c72
commit
c08996515b
|
@ -682,7 +682,18 @@ public class LookupRecord extends AbstractProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
final FieldValue fieldValue = lookupFieldValues.get(0);
|
final FieldValue fieldValue = lookupFieldValues.get(0);
|
||||||
final Object coordinateValue = DataTypeUtils.convertType(fieldValue.getValue(), fieldValue.getField().getDataType(), null, null, null, fieldValue.getField().getFieldName());
|
final Object coordinateValue = DataTypeUtils.convertType(
|
||||||
|
fieldValue.getValue(),
|
||||||
|
Optional.ofNullable(fieldValue.getField())
|
||||||
|
.map(RecordField::getDataType)
|
||||||
|
.orElse(DataTypeUtils.inferDataType(fieldValue.getValue(), RecordFieldType.STRING.getDataType())),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
Optional.ofNullable(fieldValue.getField())
|
||||||
|
.map(RecordField::getFieldName)
|
||||||
|
.orElse(coordinateKey)
|
||||||
|
);
|
||||||
lookupCoordinates.put(coordinateKey, coordinateValue);
|
lookupCoordinates.put(coordinateKey, coordinateValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -569,6 +569,19 @@ public class TestLookupRecord {
|
||||||
out.assertContentEquals(new File("src/test/resources/TestLookupRecord/lookup-array-output-unmatched.json").toPath());
|
out.assertContentEquals(new File("src/test/resources/TestLookupRecord/lookup-array-output-unmatched.json").toPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLiteralCoordinate() {
|
||||||
|
lookupService.addValue("lookupKey", "lookupValue");
|
||||||
|
|
||||||
|
runner.setProperty("lookup", "toString('lookupKey', 'UTF-8')");
|
||||||
|
|
||||||
|
runner.enqueue("");
|
||||||
|
runner.run();
|
||||||
|
|
||||||
|
runner.assertAllFlowFilesTransferred(LookupRecord.REL_MATCHED, 1);
|
||||||
|
}
|
||||||
|
|
||||||
private static class MapLookup extends AbstractControllerService implements StringLookupService {
|
private static class MapLookup extends AbstractControllerService implements StringLookupService {
|
||||||
protected final Map<String, String> values = new HashMap<>();
|
protected final Map<String, String> values = new HashMap<>();
|
||||||
private Map<String, Object> expectedContext;
|
private Map<String, Object> expectedContext;
|
||||||
|
|
Loading…
Reference in New Issue