diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/grok/GrokRecordReader.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/grok/GrokRecordReader.java index e7d81e41de..b7c397116a 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/grok/GrokRecordReader.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/grok/GrokRecordReader.java @@ -48,6 +48,7 @@ public class GrokRecordReader implements RecordReader { private RecordSchema schema; private String nextLine; + Map nextMap = null; static final String STACK_TRACE_COLUMN_NAME = "stackTrace"; static final String RAW_MESSAGE_NAME = "_raw"; @@ -74,10 +75,13 @@ public class GrokRecordReader implements RecordReader { @Override public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields) throws IOException, MalformedRecordException { - Map valueMap = null; + Map valueMap = nextMap; + nextMap = null; StringBuilder raw = new StringBuilder(); + int iterations = 0; while (valueMap == null || valueMap.isEmpty()) { + iterations++; final String line = nextLine == null ? reader.readLine() : nextLine; raw.append(line); nextLine = null; // ensure that we don't process nextLine again @@ -90,6 +94,10 @@ public class GrokRecordReader implements RecordReader { valueMap = match.toMap(); } + if (iterations == 0 && nextLine != null) { + raw.append(nextLine); + } + // Read the next line to see if it matches the pattern (in which case we will simply leave it for // the next call to nextRecord()) or we will attach it to the previously read record. String stackTrace = null; @@ -111,6 +119,7 @@ public class GrokRecordReader implements RecordReader { } } else { // The next line matched our pattern. + nextMap = nextValueMap; break; } }