Add JsonInputFormat option to assume newline delimited JSON, improve parse exception handling for multiline JSON#13089
Conversation
|
I think the new option |
|
Does this need to be documented and/or surfaced in the console? |
…handling for non-NDJSON
|
@FrankChen021 Hm, I'm inclined to keep the internal @vogievetsky I added some docs for the new properties |
| * 1. a JSON string of an object in a line or multiple lines(such as pretty-printed JSON text) | ||
| * 2. multiple JSON object strings concated by white space character(s) | ||
| * <p> | ||
| * If an input string contains invalid JSON syntax, any valid JSON objects found prior to encountering the invalid |
There was a problem hiding this comment.
Wonder whether we can distinguish the failure is due to JSON syntax error or data field in wrong format (e.g. wrong Timestamp format).
If it's due to field in wrong format then we can continue to parse the rest.
There was a problem hiding this comment.
Timestamp in wrong format errors are special, in that Druid requires a valid __time field. For other columns, such parse errors would be detected at a later stage, and wouldn't run into the same issue of preventing other events from being ingested
The JSON syntax errors here are errors where malformed JSON syntax prevents the event from being deserialized at all into a map.
| } | ||
| this.lineSplittable = lineSplittable; | ||
| this.assumeNewlineDelimited = assumeNewlineDelimited != null && assumeNewlineDelimited; | ||
| this.useJsonNodeReader = useJsonNodeReader != null && useJsonNodeReader; |
There was a problem hiding this comment.
The description for this property above seems to indicate that it should be used for non-newline delimited JSON. Would assumeNewLineDelimted true interfere with this / should this be forced to false if assumeNewLineDelimted is true?
There was a problem hiding this comment.
seems like maybe it would be an error to indicate useJsonNodeReader if assumeNewLineDelimted is set, though ignoring it seems ok too 🤷
There was a problem hiding this comment.
okay, that makes sense, I'll have it be an error
| return this.lineSplittable ? | ||
| new JsonLineReader(inputRowSchema, source, getFlattenSpec(), objectMapper, keepNullColumns) : | ||
| new JsonReader(inputRowSchema, source, getFlattenSpec(), objectMapper, keepNullColumns); | ||
| if (this.lineSplittable || this.assumeNewlineDelimited) { |
There was a problem hiding this comment.
When would lineSplitable be false, but the the data is actually newLineDelimited? Does this situation arise when you have a batch of new line delimited json events being ingested at one time, for example?
There was a problem hiding this comment.
lineSplittable is used as an indicator from the task implementation as to whether it expects the input to be newline delimited (and thus use either JsonLineReader or JsonReader). Prior to this patch, batch tasks would always use newline delimited (JsonLineReader) and streaming tasks would always use the multiline parser (JsonReader).
With this patch, batch tasks would still always use newline delimited, while for streaming tasks the behavior is configurable (controlled by the new asssumeNewlineDelimited property)
| } | ||
| this.lineSplittable = lineSplittable; | ||
| this.assumeNewlineDelimited = assumeNewlineDelimited != null && assumeNewlineDelimited; | ||
| this.useJsonNodeReader = useJsonNodeReader != null && useJsonNodeReader; |
There was a problem hiding this comment.
seems like maybe it would be an error to indicate useJsonNodeReader if assumeNewLineDelimted is set, though ignoring it seems ok too 🤷
When JsonInputFormat is used for streaming ingestion, if the input string contains multiple JSON events, but there is a parse exception occurs, all events in the record will be discarded, even if some events were valid (see #10383)
This PR adds the following:
assumedNewlineDelimitedoption for JsonInputFormat that can be used when the input is known to be newline-delimited JSON. This will force the input format to create aJsonLineReader, which can parse lines independently, so that a parse exception on one line will not prevent other valid lines from being ingested.useJsonNodeReaderoption for JsonInputFormat. If true, instead of creating aJsonReader, the input format will create a newJsonNodeReaderfor parsing multi-line JSON. This new parser splits an input string intoJsonNodeobjects and parses them one by one intoInputRow. This allows valid events found prior to a parse exception to be ingested. Potentially valid events after invalid JSON syntax is encountered will still be ignored. This also prevents valid JSON events with an unparseable timestamp from causing other events in the same input string to be discarded.This PR has: