[jira] [Comment Edited] (CSV-239) Cannot get headers in column order from CSVRecord

2019-05-20 Thread Dave Moten (JIRA)


[ 
https://issues.apache.org/jira/browse/CSV-239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16844380#comment-16844380
 ] 

Dave Moten edited comment on CSV-239 at 5/20/19 11:27 PM:
--

Yep, the unmodifiableList change looks good. What about getCSVParser -> 
getParser?


was (Author: davidmoten2):
Yep, the unmodifiableList change looks good. What about getCVSParser -> 
getParser?

> Cannot get headers in column order from CSVRecord
> -
>
> Key: CSV-239
> URL: https://issues.apache.org/jira/browse/CSV-239
> Project: Commons CSV
>  Issue Type: Improvement
>  Components: Parser
>Affects Versions: 1.6
>Reporter: Dave Moten
>Priority: Minor
>
> I have a use case where I read many lines from an arbitrary csv file with a 
> given CSVFormat as List, transform that list and then want to 
> write the transformed list to another file. 
> When I specify the format as CSVFormat.DEFAULT.withFirstRecordAsHeader() the 
> headers from the first line are available in the CSVRecord object via the 
> CSVRecord.toMap object but their column positions are not (the iteration of 
> the returned map does not reflect column order). Consequently I cannot write 
> a header line in the correct order to the output csv file (which I do when 
> the first CSVRecord is to be written).
> Another option would be to be to ensure that the CSVPrinter object writes the 
> header on the first call to CSVPrinter.printRecord but we should also be able 
> to cover the user case where we are writing to a non-csv format and we still 
> want to write the headers in the correct order. 
> My preference at minimum is that the headers with column order are available 
> from CSVRecord (after all the data to supply this is already present in 
> CVSRecord). The addition of a method `getHeaders` returning a `List` 
> would do the job. I'm happy to submit a PR if desired.
> I've marked this as of minor importance but I think it's a pretty important 
> flaw in the library at the moment that prevents event the simplest of 
> round-trip (read then write) scenarios when the headers are read from the 
> file rather than known up-front.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Comment Edited] (CSV-239) Cannot get headers in column order from CSVRecord

2019-05-19 Thread Gary Gregory (JIRA)


[ 
https://issues.apache.org/jira/browse/CSV-239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16843538#comment-16843538
 ] 

Gary Gregory edited comment on CSV-239 at 5/19/19 8:44 PM:
---

Alternatively, we could add getHeaderNames() to CSVParser and drop it 
completely from CSVRecord. That would make the information available, just not 
on each record. Thoughts?

There is no hard-core process. For contributors, it is nicer for us to get 
contributions through GitHub. 

We could also replace both headerMap and headerNames with a pointer back to the 
parser.


was (Author: garydgregory):
Alternatively, we could add getHeaderNames() to CSVParser and drop it 
completely from CSVRecord. That would make the information available, just not 
on each record. Thoughts?

There is no hard-core process. For contributors, it is nicer for us to get 
contributions through GitHub. 

> Cannot get headers in column order from CSVRecord
> -
>
> Key: CSV-239
> URL: https://issues.apache.org/jira/browse/CSV-239
> Project: Commons CSV
>  Issue Type: Improvement
>  Components: Parser
>Affects Versions: 1.6
>Reporter: Dave Moten
>Priority: Minor
>
> I have a use case where I read many lines from an arbitrary csv file with a 
> given CSVFormat as List, transform that list and then want to 
> write the transformed list to another file. 
> When I specify the format as CSVFormat.DEFAULT.withFirstRecordAsHeader() the 
> headers from the first line are available in the CSVRecord object via the 
> CSVRecord.toMap object but their column positions are not (the iteration of 
> the returned map does not reflect column order). Consequently I cannot write 
> a header line in the correct order to the output csv file (which I do when 
> the first CSVRecord is to be written).
> Another option would be to be to ensure that the CSVPrinter object writes the 
> header on the first call to CSVPrinter.printRecord but we should also be able 
> to cover the user case where we are writing to a non-csv format and we still 
> want to write the headers in the correct order. 
> My preference at minimum is that the headers with column order are available 
> from CSVRecord (after all the data to supply this is already present in 
> CVSRecord). The addition of a method `getHeaders` returning a `List` 
> would do the job. I'm happy to submit a PR if desired.
> I've marked this as of minor importance but I think it's a pretty important 
> flaw in the library at the moment that prevents event the simplest of 
> round-trip (read then write) scenarios when the headers are read from the 
> file rather than known up-front.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Comment Edited] (CSV-239) Cannot get headers in column order from CSVRecord

2019-05-19 Thread Gary Gregory (JIRA)


[ 
https://issues.apache.org/jira/browse/CSV-239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16843448#comment-16843448
 ] 

Gary Gregory edited comment on CSV-239 at 5/19/19 2:28 PM:
---

Please see git master or a SNAPSHOT 
(https://repository.apache.org/content/repositories/snapshots/) for the new 
method {{org.apache.commons.csv.CSVRecord.getHeaderNames()}}.


was (Author: garydgregory):
Please see git master or a SNAPSHOT for the new method 
{{org.apache.commons.csv.CSVRecord.getHeaderNames()}}.

> Cannot get headers in column order from CSVRecord
> -
>
> Key: CSV-239
> URL: https://issues.apache.org/jira/browse/CSV-239
> Project: Commons CSV
>  Issue Type: Improvement
>  Components: Parser
>Affects Versions: 1.6
>Reporter: Dave Moten
>Priority: Minor
>
> I have a use case where I read many lines from an arbitrary csv file with a 
> given CSVFormat as List, transform that list and then want to 
> write the transformed list to another file. 
> When I specify the format as CSVFormat.DEFAULT.withFirstRecordAsHeader() the 
> headers from the first line are available in the CSVRecord object via the 
> CSVRecord.toMap object but their column positions are not (the iteration of 
> the returned map does not reflect column order). Consequently I cannot write 
> a header line in the correct order to the output csv file (which I do when 
> the first CSVRecord is to be written).
> Another option would be to be to ensure that the CSVPrinter object writes the 
> header on the first call to CSVPrinter.printRecord but we should also be able 
> to cover the user case where we are writing to a non-csv format and we still 
> want to write the headers in the correct order. 
> My preference at minimum is that the headers with column order are available 
> from CSVRecord (after all the data to supply this is already present in 
> CVSRecord). The addition of a method `getHeaders` returning a `List` 
> would do the job. I'm happy to submit a PR if desired.
> I've marked this as of minor importance but I think it's a pretty important 
> flaw in the library at the moment that prevents event the simplest of 
> round-trip (read then write) scenarios when the headers are read from the 
> file rather than known up-front.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)