NIFI-7178 - Handle the case when schema is not available

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes #4067.
This commit is contained in:
Zoltan Kornel Torok 2020-02-21 16:13:40 +01:00 committed by Pierre Villard
parent 49ba9e8196
commit e631851e0f
No known key found for this signature in database
GPG Key ID: BEE1599F0726E9CD
3 changed files with 7 additions and 3 deletions

View File

@ -180,7 +180,7 @@ public class JsonPathRowRecordReader extends AbstractJsonRowRecordReader {
return new MapRecord(childSchema, values); return new MapRecord(childSchema, values);
} }
if (value instanceof String) { if (dataType != null && value instanceof String) {
switch (dataType.getFieldType()) { switch (dataType.getFieldType()) {
case DATE: case DATE:
case TIME: case TIME:

View File

@ -174,6 +174,7 @@ public class TestJsonPathRowRecordReader {
final LinkedHashMap<String, JsonPath> jsonPaths = new LinkedHashMap<>(); final LinkedHashMap<String, JsonPath> jsonPaths = new LinkedHashMap<>();
jsonPaths.put("timestamp", JsonPath.compile("$.timestamp")); jsonPaths.put("timestamp", JsonPath.compile("$.timestamp"));
jsonPaths.put("field_not_in_schema", JsonPath.compile("$.field_not_in_schema"));
for (final boolean coerceTypes : new boolean[] {true, false}) { for (final boolean coerceTypes : new boolean[] {true, false}) {
try (final InputStream in = new FileInputStream(new File("src/test/resources/json/timestamp.json")); try (final InputStream in = new FileInputStream(new File("src/test/resources/json/timestamp.json"));
@ -182,6 +183,9 @@ public class TestJsonPathRowRecordReader {
final Record record = reader.nextRecord(coerceTypes, false); final Record record = reader.nextRecord(coerceTypes, false);
final Object value = record.getValue("timestamp"); final Object value = record.getValue("timestamp");
assertTrue("With coerceTypes set to " + coerceTypes + ", value is not a Timestamp", value instanceof java.sql.Timestamp); assertTrue("With coerceTypes set to " + coerceTypes + ", value is not a Timestamp", value instanceof java.sql.Timestamp);
final Object valueNotInSchema = record.getValue("field_not_in_schema");
assertTrue("field_not_in_schema should be String", valueNotInSchema instanceof String);
} }
} }
} }

View File

@ -1 +1 @@
{"timestamp": "2019/06/27 13:04:04"} {"timestamp": "2019/06/27 13:04:04", "field_not_in_schema" : "some_value"}