mirror of
https://github.com/apache/nifi.git
synced 2025-03-06 01:19:49 +00:00
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:
parent
49ba9e8196
commit
e631851e0f
@ -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:
|
||||||
@ -243,4 +243,4 @@ public class JsonPathRowRecordReader extends AbstractJsonRowRecordReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
{"timestamp": "2019/06/27 13:04:04"}
|
{"timestamp": "2019/06/27 13:04:04", "field_not_in_schema" : "some_value"}
|
Loading…
x
Reference in New Issue
Block a user