NIFI-10106 Avoid NPE in LookupRecord.createLookupCoordinates (#6111)

This commit is contained in:
tpalfy 2022-06-21 23:03:44 +02:00 committed by GitHub
parent 5febd47c72
commit c08996515b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -682,7 +682,18 @@ public class LookupRecord extends AbstractProcessor {
}
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);
}

View File

@ -569,6 +569,19 @@ public class TestLookupRecord {
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 {
protected final Map<String, String> values = new HashMap<>();
private Map<String, Object> expectedContext;