Package org.apache.druid.data.input.impl
Class JsonLineReader
- java.lang.Object
-
- org.apache.druid.data.input.IntermediateRowParsingReader<String>
-
- org.apache.druid.data.input.TextReader
-
- org.apache.druid.data.input.impl.JsonLineReader
-
- All Implemented Interfaces:
InputEntityReader
public class JsonLineReader extends TextReader
JsonLineReader
reads input text line by line and tries to convert each text line to an JSON object. Since each text line is processed indepdently, if any exception is thrown when parsing one text line, exception can be caught by callers to skip current line and continue to process next text line. This also means that each text line should be a well-formed JSON text, pretty-printed format is not allowed
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getNumHeaderLinesToSkip()
Returns the number of header lines to skip.boolean
needsToProcessHeaderLine()
Returns true if the file format needs to process a header line.List<InputRow>
parseInputRows(String line)
Parses the given line into a list ofInputRow
s.void
processHeaderLine(String line)
Processes a header line.List<Map<String,Object>>
toMap(String intermediateRow)
Converts the given intermediate row into aMap
.-
Methods inherited from class org.apache.druid.data.input.TextReader
findOrCreateColumnNames, getInputRowSchema, intermediateRowIteratorWithMetadata, source
-
Methods inherited from class org.apache.druid.data.input.IntermediateRowParsingReader
intermediateRowIterator, read, sample
-
-
-
-
Method Detail
-
parseInputRows
public List<InputRow> parseInputRows(String line) throws IOException, ParseException
Description copied from class:TextReader
Parses the given line into a list ofInputRow
s. Note that some file formats can explode a single line of input into multiple inputRows. This method will be called afterTextReader.getNumHeaderLinesToSkip()
andTextReader.processHeaderLine(java.lang.String)
.- Specified by:
parseInputRows
in classTextReader
- Throws:
ParseException
- if it cannot parse the given intermediateRow properlyIOException
-
toMap
public List<Map<String,Object>> toMap(String 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<String>
- Throws:
IOException
-
getNumHeaderLinesToSkip
public int getNumHeaderLinesToSkip()
Description copied from class:TextReader
Returns the number of header lines to skip.TextReader.processHeaderLine(java.lang.String)
will be called as many times as the returned number.- Specified by:
getNumHeaderLinesToSkip
in classTextReader
-
needsToProcessHeaderLine
public boolean needsToProcessHeaderLine()
Description copied from class:TextReader
Returns true if the file format needs to process a header line. This method will be called after skipping lines as many asTextReader.getNumHeaderLinesToSkip()
.- Specified by:
needsToProcessHeaderLine
in classTextReader
-
processHeaderLine
public void processHeaderLine(String line)
Description copied from class:TextReader
Processes a header line. This will be called ifTextReader.needsToProcessHeaderLine()
= true.- Specified by:
processHeaderLine
in classTextReader
-
-