Package org.apache.druid.data.input.impl
Class JsonNodeReader
java.lang.Object
org.apache.druid.data.input.IntermediateRowParsingReader<com.fasterxml.jackson.databind.JsonNode>
org.apache.druid.data.input.impl.JsonNodeReader
- All Implemented Interfaces:
InputEntityReader
public class JsonNodeReader
extends IntermediateRowParsingReader<com.fasterxml.jackson.databind.JsonNode>
In contrast to
JsonLineReader which processes input text line by line independently,
this class tries to split the input into a list of JsonNode objects, and then parses each JsonNode independently
into an InputRow.
The input text can be: 1. a JSON string of an object in a line or multiple lines(such as pretty-printed JSON text) 2. multiple JSON object strings concatenated by white space character(s)
If an input string contains invalid JSON syntax, any valid JSON objects found prior to encountering the invalid syntax will be successfully parsed, but parsing will not continue after the invalid syntax.
-
Method Summary
Modifier and TypeMethodDescriptionprotected CloseableIterator<com.fasterxml.jackson.databind.JsonNode>Creates an iterator of intermediate rows.parseInputRows(com.fasterxml.jackson.databind.JsonNode intermediateRow) Parses the given intermediate row into a list ofInputRows.protected InputEntitysource()toMap(com.fasterxml.jackson.databind.JsonNode intermediateRow) Converts the given intermediate row into aMap.Methods inherited from class org.apache.druid.data.input.IntermediateRowParsingReader
intermediateRowAsString, intermediateRowIteratorWithMetadata, read, sample
-
Method Details
-
intermediateRowIterator
protected CloseableIterator<com.fasterxml.jackson.databind.JsonNode> intermediateRowIterator() throws IOExceptionDescription copied from class:IntermediateRowParsingReaderCreates an iterator of intermediate rows. The returned rows will be consumed byIntermediateRowParsingReader.parseInputRows(T)andIntermediateRowParsingReader.toMap(T). Either this orIntermediateRowParsingReader.intermediateRowIteratorWithMetadata()should be implemented- Overrides:
intermediateRowIteratorin classIntermediateRowParsingReader<com.fasterxml.jackson.databind.JsonNode>- Throws:
IOException
-
source
- Overrides:
sourcein classIntermediateRowParsingReader<com.fasterxml.jackson.databind.JsonNode>- Returns:
- InputEntity which the implementation is reading from. Useful in generating informative
ParseExceptions. For example, in case ofFileEntity, file name containing erroneous records or in case ofHttpEntity, the endpoint containing the erroneous data can be attached to the error message
-
parseInputRows
protected List<InputRow> parseInputRows(com.fasterxml.jackson.databind.JsonNode intermediateRow) throws ParseException Description copied from class:IntermediateRowParsingReaderParses the given intermediate row into a list ofInputRows. This should return a non-empty list.- Specified by:
parseInputRowsin classIntermediateRowParsingReader<com.fasterxml.jackson.databind.JsonNode>- Throws:
ParseException- if it cannot parse the given intermediateRow properly
-
toMap
protected List<Map<String,Object>> toMap(com.fasterxml.jackson.databind.JsonNode intermediateRow) throws IOException Description copied from class:IntermediateRowParsingReaderConverts the given intermediate row into aMap. The returned JSON will be used by InputSourceSampler. Implementations can use any method to convert the given row into a Map. This should return a non-empty list with the same size of the list returned byIntermediateRowParsingReader.parseInputRows(T)or the returned objects will be discarded- Specified by:
toMapin classIntermediateRowParsingReader<com.fasterxml.jackson.databind.JsonNode>- Throws:
IOException
-