You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "David Guiney (Jira)" <ji...@apache.org> on 2021/06/17 21:06:00 UTC

[jira] [Updated] (CSV-274) CSVParser.iterator() does not itterate over result set as expected.

     [ https://issues.apache.org/jira/browse/CSV-274?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

David Guiney updated CSV-274:
-----------------------------
    Description: 
To return a stream of `CSVRecords` in a Spliterators, I need to call `CSVParser.getRecords().iterator()`. I worry that the `getRecords()` will load the records from the parser into memory, before creating the itterator which can be a problem with large CSV files.

My code: 
{code:java}
    public Stream<CSVRecord> convertFileToMaps(Path path) throws IOException {
        try (CSVParser parser = CSVParser.parse(path, Charset.defaultCharset(), CSVFormat.RFC4180
            .withFirstRecordAsHeader())) {
            return StreamSupport.stream(Spliterators.spliteratorUnknownSize(parser.iterator(), 0), false);
        }
}
{code}
When I collect the results of my method, it gives me
{code:java}
[]
{code}
 

If I replace `parser.iterator()` with `parser.getRecords().iterator()` then I get the desired results. Is the iterator not meant to be an iterator of the list of `CSVRecord`.

  was:
To return a stream of `CSVRecords` in a Spliterators, I need to call `CSVParser.getRecords().iterator()`. I worry that the `getRecords()` will load the records from the parser into memory, before creating the itterator which can be a problem with large CSV files.

My code: 
{code:java}
    public Stream<CSVRecord> convertFileToMaps(Path path) throws IOException {
        try (CSVParser parser = CSVParser.parse(path, Charset.defaultCharset(), CSVFormat.RFC4180
            .withFirstRecordAsHeader())) {
            return StreamSupport.stream(Spliterators.spliteratorUnknownSize(parser.iterator(), 0), false);
        }
}
{code}
When I collect the results of my method, it gives me
{code:java}
[]
{code}
If I replace `parser.iterator()` with `parser.getRecords().iterator()` then I get the desired results. Is the iterator not meant to be an iterator of the list of `CSVRecord`.


> CSVParser.iterator() does not itterate over result set as expected.
> -------------------------------------------------------------------
>
>                 Key: CSV-274
>                 URL: https://issues.apache.org/jira/browse/CSV-274
>             Project: Commons CSV
>          Issue Type: Bug
>          Components: Parser
>    Affects Versions: 1.8
>            Reporter: David Guiney
>            Priority: Major
>
> To return a stream of `CSVRecords` in a Spliterators, I need to call `CSVParser.getRecords().iterator()`. I worry that the `getRecords()` will load the records from the parser into memory, before creating the itterator which can be a problem with large CSV files.
> My code: 
> {code:java}
>     public Stream<CSVRecord> convertFileToMaps(Path path) throws IOException {
>         try (CSVParser parser = CSVParser.parse(path, Charset.defaultCharset(), CSVFormat.RFC4180
>             .withFirstRecordAsHeader())) {
>             return StreamSupport.stream(Spliterators.spliteratorUnknownSize(parser.iterator(), 0), false);
>         }
> }
> {code}
> When I collect the results of my method, it gives me
> {code:java}
> []
> {code}
>  
> If I replace `parser.iterator()` with `parser.getRecords().iterator()` then I get the desired results. Is the iterator not meant to be an iterator of the list of `CSVRecord`.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)