mirror of https://github.com/apache/nifi.git
NIFI-4967 - CSVRecordReader does not read header with specific formats
Signed-off-by: Matthew Burgess <mattyb149@apache.org> This closes #2536
This commit is contained in:
parent
c75604a564
commit
95e543d4cc
|
@ -77,6 +77,8 @@ public class CSVRecordReader implements RecordReader {
|
|||
|
||||
if (ignoreHeader) {
|
||||
withHeader = withHeader.withHeader(schema.getFieldNames().toArray(new String[0]));
|
||||
} else {
|
||||
withHeader = withHeader.withFirstRecordAsHeader();
|
||||
}
|
||||
} else {
|
||||
withHeader = csvFormat.withHeader(schema.getFieldNames().toArray(new String[0]));
|
||||
|
|
|
@ -124,6 +124,29 @@ public class TestCSVRecordReader {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExcelFormat() throws IOException, MalformedRecordException {
|
||||
final List<RecordField> fields = new ArrayList<RecordField>();
|
||||
fields.add(new RecordField("fieldA", RecordFieldType.STRING.getDataType()));
|
||||
fields.add(new RecordField("fieldB", RecordFieldType.STRING.getDataType()));
|
||||
final RecordSchema schema = new SimpleRecordSchema(fields);
|
||||
|
||||
final String headerLine = "fieldA,fieldB";
|
||||
final String inputRecord = "valueA,valueB";
|
||||
final String csvData = headerLine + "\n" + inputRecord;
|
||||
final byte[] inputData = csvData.getBytes();
|
||||
|
||||
try (final InputStream bais = new ByteArrayInputStream(inputData);
|
||||
final CSVRecordReader reader = createReader(bais, schema, CSVFormat.EXCEL)) {
|
||||
|
||||
final Object[] record = reader.nextRecord().getValues();
|
||||
final Object[] expectedValues = new Object[] {"valueA", "valueB"};
|
||||
Assert.assertArrayEquals(expectedValues, record);
|
||||
|
||||
assertNull(reader.nextRecord());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleRecords() throws IOException, MalformedRecordException {
|
||||
final List<RecordField> fields = getDefaultFields();
|
||||
|
|
Loading…
Reference in New Issue