xavifeds8 commented on code in PR #2399:
URL: https://github.com/apache/phoenix/pull/2399#discussion_r3254597567


##########
phoenix-core-server/src/main/java/org/apache/phoenix/mapreduce/CsvToKeyValueMapper.java:
##########
@@ -89,17 +90,21 @@ static class CsvLineParser implements LineParser<CSVRecord> 
{
     private final CSVFormat csvFormat;
 
     CsvLineParser(Character fieldDelimiter, Character quote, Character escape) 
{
-      this.csvFormat = 
CSVFormat.DEFAULT.withIgnoreEmptyLines(true).withDelimiter(fieldDelimiter)
-        .withEscape(escape).withQuote(quote);
+      this.csvFormat = CSVFormat.DEFAULT.builder().setIgnoreEmptyLines(true)
+        .setDelimiter(fieldDelimiter).setEscape(escape).setQuote(quote).get();
     }
 
     @Override
     public CSVRecord parse(String input) throws IOException {
       // TODO Creating a new parser for each line seems terribly inefficient 
but
       // there's no public way to parse single lines via commons-csv. We 
should update
       // it to create a LineParser class like this one.
-      CSVParser csvParser = new CSVParser(new StringReader(input), csvFormat);
-      return Iterables.getFirst(csvParser, null);
+      try (CSVParser csvParser =
+        CSVParser.builder().setFormat(csvFormat).setReader(new 
StringReader(input)).get()) {
+        return Iterables.getFirst(csvParser, null);
+      } catch (UncheckedIOException e) {

Review Comment:
   Hey @NihalJain 
   
https://github.com/apache/commons-csv/blob/6f93c7edfa0f758f757227b1d30588411fdbf669/src/main/java/org/apache/commons/csv/CSVParser.java#L234
   
   Here in  1.14.1 in csv-commons CSVParser IOException is wraped with  
UncheckedIOException.
   
   also have added a UT to verify this behaviour 
https://github.com/apache/phoenix/pull/2399/changes/25be3490d71fdc1f4ef85d4f66400f1fe2cec46d
   
   [INFO] -------------------------------------------------------
   [INFO]  T E S T S
   [INFO] -------------------------------------------------------
   [INFO] Running org.apache.phoenix.mapreduce.CsvToKeyValueMapperTest
   [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.064 
s -- in org.apache.phoenix.mapreduce.CsvToKeyValueMapperTest
   [INFO] 
   [INFO] Results:
   [INFO] 
   [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
   [INFO] 
   [INFO] 
------------------------------------------------------------------------
   [INFO] BUILD SUCCESS
   [INFO] 
------------------------------------------------------------------------
   [INFO] Total time:  23.525 s
   [INFO] Finished at: 2026-05-18T12:02:52+05:30
   [INFO] 
------------------------------------------------------------------------
   
   % cat 
phoenix-core/target/surefire-reports/org.apache.phoenix.mapreduce.CsvToKeyValueMapperTest-output.txt
   
   **Exception type: java.io.UncheckedIOException
   Message: org.apache.commons.csv.CSVException: (startline 1) EOF reached 
before encapsulated token finished
   Cause type: org.apache.commons.csv.CSVException
   Cause message: (startline 1) EOF reached before encapsulated token finished
   phoenix %** 



-- 
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]

Reply via email to