Repository: nifi
Updated Branches:
refs/heads/master f50a07ec8 -> 406db4867
NIFI-4702: When we check the next line for matches in Grok Reader, store the Map that is returned
so that we don't have to re-evaluate the regexes the next time that nextRecord() is called
Signed-off-by: Matthew Burgess <mattyb149@apache.org>
This closes #2349
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/406db486
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/406db486
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/406db486
Branch: refs/heads/master
Commit: 406db4867a60d830218de70e00ad7b9f9686b54a
Parents: f50a07e
Author: Mark Payne <markap14@hotmail.com>
Authored: Mon Dec 18 09:29:52 2017 -0500
Committer: Matthew Burgess <mattyb149@apache.org>
Committed: Mon Dec 18 09:41:05 2017 -0500
----------------------------------------------------------------------
.../main/java/org/apache/nifi/grok/GrokRecordReader.java | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/406db486/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/grok/GrokRecordReader.java
----------------------------------------------------------------------
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 e7d81e4..b7c3971 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<String, Object> 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<String, Object> valueMap = null;
+ Map<String, Object> 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;
}
}
|