Package org.apache.druid.data.input.impl
Class JsonReader
- java.lang.Object
-
- org.apache.druid.data.input.IntermediateRowParsingReader<InputEntity>
-
- org.apache.druid.data.input.impl.JsonReader
-
- All Implemented Interfaces:
InputEntityReader
public class JsonReader extends IntermediateRowParsingReader<InputEntity>
In contrast toJsonLineReader
which processes input text line by line independently, this class tries to parse the input text as a whole to an array of objects. 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 concated by white space character(s) For case 2, what should be noticed is that if an exception is thrown when parsing one JSON string, the rest JSON text will all be ignored For more information, see: https://github.com/apache/druid/pull/10383
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
intermediateRowAsString(InputEntity entity)
String representation of an intermediate row.protected CloseableIterator<InputEntity>
intermediateRowIterator()
Creates an iterator of intermediate rows.protected List<InputRow>
parseInputRows(InputEntity entity)
Parses the given intermediate row into a list ofInputRow
s.protected InputEntity
source()
protected List<Map<String,Object>>
toMap(InputEntity entity)
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<InputEntity> intermediateRowIterator()
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<InputEntity>
-
source
protected InputEntity source()
- Overrides:
source
in classIntermediateRowParsingReader<InputEntity>
- 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
-
intermediateRowAsString
protected String intermediateRowAsString(@Nullable InputEntity entity)
Description copied from class:IntermediateRowParsingReader
String representation of an intermediate row. Used for error messages.- Overrides:
intermediateRowAsString
in classIntermediateRowParsingReader<InputEntity>
-
parseInputRows
protected List<InputRow> parseInputRows(InputEntity entity) throws IOException, 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<InputEntity>
- Throws:
ParseException
- if it cannot parse the given intermediateRow properlyIOException
-
toMap
protected List<Map<String,Object>> toMap(InputEntity entity) 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<InputEntity>
- Throws:
IOException
-
-