[
https://issues.apache.org/jira/browse/CSV-264?focusedWorklogId=620835&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-620835
]
ASF GitHub Bot logged work on CSV-264:
--------------------------------------
Author: ASF GitHub Bot
Created on: 09/Jul/21 02:06
Start Date: 09/Jul/21 02:06
Worklog Time Spent: 10m
Work Description: SethFalco commented on pull request #114:
URL: https://github.com/apache/commons-csv/pull/114#issuecomment-876858602
I didn't see it documented, figured the easiest way to find out would be to
just test it.
It currently uses the last column with the given name.
> What happens/should happen for each enum value when you call
CSVRecord.get(String).
| A | A
|---|---
| 1 | 2
| 3 | 4
```java
List<CSVRecord> records = parser.getRecords();
for (CSVRecord record : records)
System.out.println(record.get("A"));
// 2
// 4
```
> What happens/should happen for each enum value when you call
CSVRecord.toMap().
| A | A | B | B
|---|---|---|---
| 1 | 2 | 5 | 6
| 3 | 4 | 7 | 8
```java
List<CSVRecord> records = parser.getRecords();
for (CSVRecord record : records) {
Map<String, String> map = record.toMap();
System.out.println(map);
}
// {A=2, B=6}
// {A=4, B=8}
```
I think we could add a docstring on `CSVRecord#get` and `CSVRecord#toMap` to
clarify this.
We could also add something on `CSVFormat#setDuplicateHeaderMode`?
It might be a good idea to add test cases to cover this scenario, if it'll
become documented behavior.
Mind if I do this in a separate PR?
I'd say it counts as a separate change from this one, so it'll keep things
tidier.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 620835)
Time Spent: 3h 20m (was: 3h 10m)
> Duplicate empty header names are allowed even with
> `.withAllowDuplicateHeaderNames(false)`
> ------------------------------------------------------------------------------------------
>
> Key: CSV-264
> URL: https://issues.apache.org/jira/browse/CSV-264
> Project: Commons CSV
> Issue Type: Bug
> Components: Parser
> Affects Versions: 1.8
> Reporter: Sagar Tiwari
> Priority: Major
> Time Spent: 3h 20m
> Remaining Estimate: 0h
>
> I'm trying to parse to parse a csv like this:
>
> {{CSVFormat.DEFAULT}}
> {{ .withHeader()}}
> {{ .withAllowDuplicateHeaderNames(false)}}
> {{ .withAllowMissingColumnNames()}}
> {{ .parse(InputStreamReader(FileInputStream(fl)))}}
>
> One would expect this code to throw an error if the following csv is given as
> input:
>
>
> {{"","a",""}}
> {{"1","X","3"}}
> {{"3","Y","4"}}
>
> But it doesn't, and asking for `record.get("")` gives the value from the
> second column. The first column is ignored.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)