public class CSVRecordReader extends LineRecordReader
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_DELIMITER |
protected String |
delimiter |
static String |
DELIMITER |
protected String |
quote |
static String |
QUOTE |
static String |
QUOTE_HANDLING_DELIMITER
A regex delimiter that can parse quotes (string literals) that may have commas in them: http://stackoverflow.com/a/1757107/523744
Note: This adds considerable overhead compared to the default "," delimiter, and should only be used when necessary.
|
static String |
SKIP_NUM_LINES |
protected int |
skipNumLines |
conf, inputSplit, lineIndex, locations, splitIndexlistenersAPPEND_LABEL, LABELS, NAME_SPACE| Constructor and Description |
|---|
CSVRecordReader() |
CSVRecordReader(int skipNumLines)
Skip first n lines
|
CSVRecordReader(int skipNumLines,
String delimiter)
Skip lines and use delimiter
|
CSVRecordReader(int skipNumLines,
String delimiter,
String quote)
Skip lines, use delimiter, and strip quotes
|
| Modifier and Type | Method and Description |
|---|---|
void |
initialize(Configuration conf,
InputSplit split)
Called once at initialization.
|
List<Record> |
loadFromMetaData(List<RecordMetaData> recordMetaDatas)
Load multiple records from the given a list of
RecordMetaData instances |
Record |
loadFromMetaData(RecordMetaData recordMetaData)
Load a single record from the given
RecordMetaData instanceNote: that for data that isn't splittable (i.e., text data that needs to be scanned/split), it is more efficient to load multiple records at once using RecordReader.loadFromMetaData(List) |
List<Writable> |
next()
Get the next record
|
Record |
nextRecord()
Similar to
RecordReader.next(), but returns a Record object, that may include metadata such as the source
of the data |
protected void |
onLocationOpen(URI location) |
protected List<Writable> |
parseLine(String line) |
List<Writable> |
record(URI uri,
DataInputStream dataInputStream)
Load the record from the given DataInputStream
Unlike
RecordReader.next() the internal state of the RecordReader is not modified
Implementations of this method should not close the DataInputStream |
void |
reset()
Reset record reader iterator
|
close, closeIfRequired, getConf, getIterator, getLabels, hasNext, initialize, setConfgetListeners, invokeListeners, setListeners, setListenerspublic static final String QUOTE_HANDLING_DELIMITER
protected int skipNumLines
protected String delimiter
protected String quote
public static final String DEFAULT_DELIMITER
public static final String SKIP_NUM_LINES
public static final String DELIMITER
public static final String QUOTE
public CSVRecordReader(int skipNumLines)
skipNumLines - the number of lines to skippublic CSVRecordReader(int skipNumLines,
String delimiter)
skipNumLines - the number of lines to skipdelimiter - the delimiterpublic CSVRecordReader(int skipNumLines,
String delimiter,
String quote)
skipNumLines - the number of lines to skipdelimiter - the delimiterquote - the quote to strippublic CSVRecordReader()
public void initialize(Configuration conf, InputSplit split) throws IOException, InterruptedException
RecordReaderinitialize in interface RecordReaderinitialize in class LineRecordReaderconf - a configuration for initializationsplit - the split that defines the range of records to readIOExceptionInterruptedExceptionpublic List<Writable> next()
RecordReadernext in interface RecordReadernext in class LineRecordReaderpublic Record nextRecord()
RecordReaderRecordReader.next(), but returns a Record object, that may include metadata such as the source
of the datanextRecord in interface RecordReadernextRecord in class LineRecordReaderpublic Record loadFromMetaData(RecordMetaData recordMetaData) throws IOException
RecordReaderRecordMetaData instanceRecordReader.loadFromMetaData(List)loadFromMetaData in interface RecordReaderloadFromMetaData in class LineRecordReaderrecordMetaData - Metadata for the record that we want to load fromIOException - If I/O error occurs during loadingpublic List<Record> loadFromMetaData(List<RecordMetaData> recordMetaDatas) throws IOException
RecordReaderRecordMetaData instancesloadFromMetaData in interface RecordReaderloadFromMetaData in class LineRecordReaderrecordMetaDatas - Metadata for the records that we want to load fromIOException - If I/O error occurs during loadingpublic List<Writable> record(URI uri, DataInputStream dataInputStream) throws IOException
RecordReaderRecordReader.next() the internal state of the RecordReader is not modified
Implementations of this method should not close the DataInputStreamrecord in interface RecordReaderrecord in class LineRecordReaderIOException - if error occurs during reading from the input streampublic void reset()
RecordReaderreset in interface RecordReaderreset in class LineRecordReaderprotected void onLocationOpen(URI location)
onLocationOpen in class LineRecordReaderCopyright © 2017. All rights reserved.