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 toJsonLineReaderwhich 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 StringintermediateRowAsString(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 ofInputRows.protected InputEntitysource()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: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<InputEntity>
-
source
protected InputEntity source()
- Overrides:
sourcein classIntermediateRowParsingReader<InputEntity>- 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
-
intermediateRowAsString
protected String intermediateRowAsString(@Nullable InputEntity entity)
Description copied from class:IntermediateRowParsingReaderString representation of an intermediate row. Used for error messages.- Overrides:
intermediateRowAsStringin classIntermediateRowParsingReader<InputEntity>
-
parseInputRows
protected List<InputRow> parseInputRows(InputEntity entity) throws IOException, 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<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: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<InputEntity>- Throws:
IOException
-
-