ekovacs commented on a change in pull request #3282: NIFI-5983: handling parse
problems in recordReader implementations
URL: https://github.com/apache/nifi/pull/3282#discussion_r253749342
##########
File path:
nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/csv/CSVRecordReader.java
##########
@@ -72,45 +74,49 @@ public CSVRecordReader(final InputStream in, final
ComponentLog logger, final Re
@Override
public Record nextRecord(final boolean coerceTypes, final boolean
dropUnknownFields) throws IOException, MalformedRecordException {
- final RecordSchema schema = getSchema();
-
- final List<RecordField> recordFields = getRecordFields();
- final int numFieldNames = recordFields.size();
-
- for (final CSVRecord csvRecord : csvParser) {
- final Map<String, Object> values = new
LinkedHashMap<>(recordFields.size() * 2);
- for (int i = 0; i < csvRecord.size(); i++) {
- final String rawValue = csvRecord.get(i);
- final String rawFieldName;
- final DataType dataType;
- if (i >= numFieldNames) {
- if (!dropUnknownFields) {
- values.put("unknown_field_index_" + i, rawValue);
+ try {
+ final RecordSchema schema = getSchema();
+
+ final List<RecordField> recordFields = getRecordFields();
+ final int numFieldNames = recordFields.size();
+ for (final CSVRecord csvRecord : csvParser) {
+ final Map<String, Object> values = new
LinkedHashMap<>(recordFields.size() * 2);
+ for (int i = 0; i < csvRecord.size(); i++) {
+ final String rawValue = csvRecord.get(i);
+
+ final String rawFieldName;
+ final DataType dataType;
+ if (i >= numFieldNames) {
+ if (!dropUnknownFields) {
+ values.put("unknown_field_index_" + i, rawValue);
+ }
+
+ continue;
+ } else {
+ final RecordField recordField = recordFields.get(i);
+ rawFieldName = recordField.getFieldName();
+ dataType = recordField.getDataType();
}
- continue;
- } else {
- final RecordField recordField = recordFields.get(i);
- rawFieldName = recordField.getFieldName();
- dataType = recordField.getDataType();
- }
+ final Object value;
+ if (coerceTypes) {
+ value = convert(rawValue, dataType, rawFieldName);
+ } else {
+ // The CSV Reader is going to return all fields as
Strings, because CSV doesn't have any way to
+ // dictate a field type. As a result, we will use the
schema that we have to attempt to convert
+ // the value into the desired type if it's a simple
type.
+ value = convertSimpleIfPossible(rawValue, dataType,
rawFieldName);
+ }
- final Object value;
- if (coerceTypes) {
- value = convert(rawValue, dataType, rawFieldName);
- } else {
- // The CSV Reader is going to return all fields as
Strings, because CSV doesn't have any way to
- // dictate a field type. As a result, we will use the
schema that we have to attempt to convert
- // the value into the desired type if it's a simple type.
- value = convertSimpleIfPossible(rawValue, dataType,
rawFieldName);
+ values.put(rawFieldName, value);
}
- values.put(rawFieldName, value);
+ return new MapRecord(schema, values, coerceTypes,
dropUnknownFields);
}
-
- return new MapRecord(schema, values, coerceTypes,
dropUnknownFields);
+ } catch (Throwable e) {
Review comment:
done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services