suddendust commented on a change in pull request #7237:
URL: https://github.com/apache/pinot/pull/7237#discussion_r690900871



##########
File path: 
pinot-plugins/pinot-input-format/pinot-csv/src/test/java/org/apache/pinot/plugin/inputformat/csv/CSVRecordReaderTest.java
##########
@@ -103,4 +105,74 @@ protected void checkValue(RecordReader recordReader, 
List<Map<String, Object>> e
     }
     Assert.assertFalse(recordReader.hasNext());
   }
+
+  @Test
+  public void testInvalidDelimiterInHeader() {
+    //setup
+    CSVRecordReaderConfig csvRecordReaderConfig = new CSVRecordReaderConfig();
+    csvRecordReaderConfig.setMultiValueDelimiter(CSV_MULTI_VALUE_DELIMITER);
+    
csvRecordReaderConfig.setHeader("col1;col2;col3;col4;col5;col6;col7;col8;col9;col10");
+    csvRecordReaderConfig.setDelimiter(',');
+    CSVRecordReader csvRecordReader = new CSVRecordReader();
+
+    //execute and assert
+    Assert.assertThrows(IllegalArgumentException.class,
+        () -> csvRecordReader.init(_dataFile, null, csvRecordReaderConfig));
+  }
+
+  @Test
+  public void testValidDelimiterInHeader()
+      throws IOException {
+    //setup
+    CSVRecordReaderConfig csvRecordReaderConfig = new CSVRecordReaderConfig();
+    csvRecordReaderConfig.setMultiValueDelimiter(CSV_MULTI_VALUE_DELIMITER);
+    
csvRecordReaderConfig.setHeader("col1,col2,col3,col4,col5,col6,col7,col8,col9,col10");
+    csvRecordReaderConfig.setDelimiter(',');
+    CSVRecordReader csvRecordReader = new CSVRecordReader();
+
+    //read all fields
+    //execute and assert
+    csvRecordReader.init(_dataFile, null, csvRecordReaderConfig);
+    Assert.assertTrue(csvRecordReader.hasNext());
+  }
+
+  /**
+   * When CSV records contain a single value, then no exception should be 
throw while initialising.
+   * This test requires a different setup from the rest of the tests as it 
requires a single-column
+   * CSV. Therefore, we re-write already generated records into a new file, 
but only the first
+   * column.
+   *
+   * @throws IOException
+   */
+  @Test
+  public void testHeaderDelimiterSingleColumn()
+      throws IOException {
+    //setup
+
+    //create a single value CSV
+    Schema pinotSchema = getPinotSchema();
+    //write only the first column in the schema
+    String column = pinotSchema.getColumnNames().toArray(new String[0])[0];
+    //use a different file name so that other tests aren't affected
+    File file = new File(_tempDir, "data1.csv");
+    try (FileWriter fileWriter = new FileWriter(file);
+        CSVPrinter csvPrinter = new CSVPrinter(fileWriter, 
CSVFormat.DEFAULT.withHeader(column))) {
+      for (Map<String, Object> r : _records) {
+        Object[] record = new Object[1];
+        for (int i = 0; i < 1; i++) {

Review comment:
       Ah, I had copied this piece of code and just changed the number of 
iterations from recordsMapSize to 1. Addressed.




-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to