[ 
https://issues.apache.org/jira/browse/CSV-290?focusedWorklogId=812226&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-812226
 ]

ASF GitHub Bot logged work on CSV-290:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 26/Sep/22 20:29
            Start Date: 26/Sep/22 20:29
    Worklog Time Spent: 10m 
      Work Description: angusdev commented on PR #265:
URL: https://github.com/apache/commons-csv/pull/265#issuecomment-1258595192

   Tested the behaviour of import and export are consistent.
   
   Test case: export csv/tsv from PostgreSQL, read by commons-cvs and write to 
new csv/tsv, import to PostgreSQL, export csv/tsv again. compare the 1st and 
2nd export file
   
   ```sql
   drop table COMMONS_CSV_PSQL_TEST;
   create table COMMONS_CSV_PSQL_TEST (ID INTEGER, COL1 VARCHAR, COL2 VARCHAR, 
COL3 VARCHAR, COL4 VARCHAR);
   insert into COMMONS_CSV_PSQL_TEST select 1, 'abc', 'test line 1' || chr(10) 
|| 'test line 2', null, '';
   insert into COMMONS_CSV_PSQL_TEST select 2, 'xyz', '\b:' || chr(8) || ' \n:' 
|| chr(10) || ' \r:' || chr(13), 'a', 'b';
   insert into COMMONS_CSV_PSQL_TEST values (3, 'a', 'b,c,d', '"quoted"', 'e');
   copy COMMONS_CSV_PSQL_TEST to '/tmp/psql.csv' with (FORMAT CSV);
   copy COMMONS_CSV_PSQL_TEST to '/tmp/psql.tsv';
   ```
   
   use commons-csv to read '/tmp/psql.csv' and write to '/tmp/outpsql.csv', 
same for 'psql.tsv'
   
   ```sql
   truncate table COMMONS_CSV_PSQL_TEST;
   copy COMMONS_CSV_PSQL_TEST(ID, COL1, COL2, COL3, COL4) from 
'/tmp/outpsql.csv' with (FORMAT CSV);
   copy COMMONS_CSV_PSQL_TEST to '/tmp/psql2.csv' with (FORMAT CSV);
   
   truncate table COMMONS_CSV_PSQL_TEST;
   copy COMMONS_CSV_PSQL_TEST(ID, COL1, COL2, COL3, COL4) from 
'/tmp/outpsql.tsv';
   copy COMMONS_CSV_PSQL_TEST to '/tmp/psql2.tsv';
   ```
   
   diff /tmp/psql.csv /tmp/psql2.csv
   (no difference)
   
   diff /tmp/psql.tsv /tmp/psql2.tsv
   (no difference)




Issue Time Tracking
-------------------

    Worklog Id:     (was: 812226)
    Time Spent: 1h  (was: 50m)

> Produced CSV using PostgreSQL format cannot be read
> ---------------------------------------------------
>
>                 Key: CSV-290
>                 URL: https://issues.apache.org/jira/browse/CSV-290
>             Project: Commons CSV
>          Issue Type: Bug
>          Components: Parser
>    Affects Versions: 1.6, 1.9.0
>            Reporter: Anatoliy Artemenko
>            Priority: Major
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> {code:java}
> // code placeholder
> {code}
> CSV, produced using printer:
>  
> CSVPrinter printer = new CSVPrinter(sw, 
> CSVFormat.POSTGRESQL_CSV.withFirstRecordAsHeader());
>  
> cannot be be read with same format parser:
>  
> CSVParser parser = new CSVParser(new StringReader(sw.toString()), 
> CSVFormat.POSTGRESQL_CSV.withFirstRecordAsHeader());
>  
> To reproduce: 
>  
> {code:java}
> StringWriter sw = new StringWriter(); 
> CSVPrinter printer = new CSVPrinter(sw, 
> CSVFormat.POSTGRESQL_CSV.withFirstRecordAsHeader());  
> printer.printRecord("column1", "column2"); 
> printer.printRecord("v11", "v12"); 
> printer.printRecord("v21", "v22");  
> printer.close();  
> CSVParser parser = new CSVParser(new StringReader(sw.toString()), 
> CSVFormat.POSTGRESQL_CSV.withFirstRecordAsHeader());  
> System.out.println("headers: " + 
> Arrays.equals(parser.getHeaderNames().toArray(), new String[] {"column1", 
> "column2"}));  
> Iterator<CSVRecord> i = parser.iterator(); 
> System.out.println("row: " + Arrays.equals(i.next().toList().toArray(), new 
> String[] {"v11", "v12"})); 
> System.out.println("row: " + Arrays.equals(i.next().toList().toArray(), new 
> String[] {"v21", "v22"}));{code}
> I'd expect the above code to work, but it fails:
> {code:java}
> java.io.IOException: (startline 1) EOF reached before encapsulated token 
> finishedjava.io.IOException: (startline 1) EOF reached before encapsulated 
> token finished 
> at org.apache.commons.csv.Lexer.parseEncapsulatedToken(Lexer.java:371) 
> at org.apache.commons.csv.Lexer.nextToken(Lexer.java:285) 
> at org.apache.commons.csv.CSVParser.nextRecord(CSVParser.java:701) 
> at org.apache.commons.csv.CSVParser.createHeaders(CSVParser.java:480) 
> at org.apache.commons.csv.CSVParser.<init>(CSVParser.java:432) 
> at org.apache.commons.csv.CSVParser.<init>(CSVParser.java:398) 
> at Test.main(Test.java:25)
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to