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 toJsonLineReader
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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected CloseableIterator<com.fasterxml.jackson.databind.JsonNode>
intermediateRowIterator()
Creates an iterator of intermediate rows.protected List<InputRow>
parseInputRows(com.fasterxml.jackson.databind.JsonNode intermediateRow)
Parses the given intermediate row into a list ofInputRow
s.protected InputEntity
source()
protected List<Map<String,Object>>
toMap(com.fasterxml.jackson.databind.JsonNode intermediateRow)
Converts the given intermediate row into aMap
.-
Methods inherited from class org.apache.druid.data.input.IntermediateRowParsingReader
intermediateRowIteratorWithMetadata, read, sample
-
-
-
-
Method Detail
-
intermediateRowIterator
protected CloseableIterator<com.fasterxml.jackson.databind.JsonNode> intermediateRowIterator() throws IOException
Description copied from class:IntermediateRowParsingReader
Creates 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:
intermediateRowIterator
in classIntermediateRowParsingReader<com.fasterxml.jackson.databind.JsonNode>
- Throws:
IOException
-
source
protected InputEntity source()
- Overrides:
source
in classIntermediateRowParsingReader<com.fasterxml.jackson.databind.JsonNode>
- Returns:
- InputEntity which the implementation is reading from. Useful in generating informative
ParseException
s. 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:IntermediateRowParsingReader
Parses the given intermediate row into a list ofInputRow
s. This should return a non-empty list.- Specified by:
parseInputRows
in 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:IntermediateRowParsingReader
Converts 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:
toMap
in classIntermediateRowParsingReader<com.fasterxml.jackson.databind.JsonNode>
- Throws:
IOException
-
-