mirror of https://github.com/apache/nifi.git
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
This commit is contained in:
parent
f50a07ec88
commit
406db4867a
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue