| 49 | import java.time.temporal.TemporalAccessor; |
| 50 | |
| 51 | public class CsvReader implements RecordReader { |
| 52 | private long rowNumber = 0; |
| 53 | private final Converter converter; |
| 54 | private final int columns; |
| 55 | private final CSVReader reader; |
| 56 | private final String nullString; |
| 57 | private final FSDataInputStream underlying; |
| 58 | private final long totalSize; |
| 59 | private final DateTimeFormatter dateTimeFormatter; |
| 60 | |
| 61 | /** |
| 62 | * Create a CSV reader |
| 63 | * @param reader the stream to read from |
| 64 | * @param input the underlying file that is only used for getting the |
| 65 | * position within the file |
| 66 | * @param size the number of bytes in the underlying stream |
| 67 | * @param schema the schema to read into |
| 68 | * @param separatorChar the character between fields |
| 69 | * @param quoteChar the quote character |
| 70 | * @param escapeChar the escape character |
| 71 | * @param headerLines the number of header lines |
| 72 | * @param nullString the string that is translated to null |
| 73 | * @param timestampFormat the timestamp format string |
| 74 | */ |
| 75 | public CsvReader(java.io.Reader reader, |
| 76 | FSDataInputStream input, |
| 77 | long size, |
| 78 | TypeDescription schema, |
| 79 | char separatorChar, |
| 80 | char quoteChar, |
| 81 | char escapeChar, |
| 82 | int headerLines, |
| 83 | String nullString, |
| 84 | String timestampFormat) { |
| 85 | this.underlying = input; |
| 86 | CSVParser parser = new CSVParserBuilder() |
| 87 | .withSeparator(separatorChar) |
| 88 | .withQuoteChar(quoteChar) |
| 89 | .withEscapeChar(escapeChar) |
| 90 | .build(); |
| 91 | this.reader = new CSVReaderBuilder(reader) |
| 92 | .withSkipLines(headerLines) |
| 93 | .withCSVParser(parser) |
| 94 | .build(); |
| 95 | this.nullString = nullString; |
| 96 | this.totalSize = size; |
| 97 | IntWritable nextColumn = new IntWritable(0); |
| 98 | this.converter = buildConverter(nextColumn, schema); |
| 99 | this.columns = nextColumn.get(); |
| 100 | this.dateTimeFormatter = DateTimeFormatter.ofPattern(timestampFormat); |
| 101 | } |
| 102 | |
| 103 | interface Converter { |
| 104 | void convert(String[] values, VectorizedRowBatch batch, int row); |
| 105 | void convert(String[] values, ColumnVector column, int row); |
| 106 | } |
| 107 | |
| 108 | @Override |
nothing calls this directly
no outgoing calls
no test coverage detected