Skip to content

Commit

Permalink
NIFI-10106 Avoid NPE in LookupRecord.createLookupCoordinates (apache#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tpalfy authored Jun 21, 2022
1 parent 5febd47 commit c089965
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,18 @@ private Map<String, Object> createLookupCoordinates(final Record record, final L
}

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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,19 @@ public void testLookupArrayKeyNotInLRS() throws InitializationException, IOExcep
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;
Expand Down

0 comments on commit c089965

Please sign in to comment.