You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Have a csv file with header row with 3 columns and two data rows, first data row with two columns, second - with three. Like this:
First name
Last name
Citizenship
John
Bobkins
Michael
Pepkins
US
While invoking 'readAllWithHeaderAsSequence' on this file, the CSVFieldNumDifferentException is thrown saying that two colums are expected but three are found. It happens because 'fieldsNum' variable in the CsvFileReader.kt is initialized based on the first data row, while it has to be initialized based on the header row.
Expected behavior
The following code has to return two rows:
@doyaaaaaken thank you.
For your convenience here is the problematic place: https://github.com/doyaaaaaken/kotlin-csv/blob/f4637eb89ed6c1d0d18b23de2405e41294a4c6a9/src/jvmMain/kotlin/com/github/doyaaaaaken/kotlincsv/client/CsvFileReader.kt#L46
Initially "fieldsNum" variable is null and while going over the first data row it is getting initialized with number of fields of this row. Normally when first data row has all the columns set there is no issue and parser works well, but when the first row doesn't have the last column(-s) set, "fieldsNum" is initialized incorrectly. I think the fix here has to be to initialize "fieldsNum" with header row number of fields ( in case "readAllWithHeaderAsSequence" is invoked and header row is present).
Please see my PR with proposed fix: #83
To reproduce
Have a csv file with header row with 3 columns and two data rows, first data row with two columns, second - with three. Like this:
While invoking 'readAllWithHeaderAsSequence' on this file, the CSVFieldNumDifferentException is thrown saying that two colums are expected but three are found. It happens because 'fieldsNum' variable in the CsvFileReader.kt is initialized based on the first data row, while it has to be initialized based on the header row.
Expected behavior
The following code has to return two rows:
Environment
The text was updated successfully, but these errors were encountered: