You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by GitBox <gi...@apache.org> on 2020/03/27 13:08:04 UTC

[GitHub] [drill] arina-ielchiieva commented on a change in pull request #2024: DRILL-7641: Convert Excel Reader to use Streaming Reader

arina-ielchiieva commented on a change in pull request #2024: DRILL-7641: Convert Excel Reader to use Streaming Reader
URL: https://github.com/apache/drill/pull/2024#discussion_r399250290
 
 

 ##########
 File path: contrib/format-excel/src/main/java/org/apache/drill/exec/store/excel/ExcelBatchReader.java
 ##########
 @@ -134,121 +131,131 @@ public ExcelBatchReader(ExcelReaderConfig readerConfig) {
   @Override
   public boolean open(FileSchemaNegotiator negotiator) {
     split = negotiator.split();
-    loader = negotiator.build();
+    ResultSetLoader loader = negotiator.build();
     rowWriter = loader.writer();
     openFile(negotiator);
     defineSchema();
     return true;
   }
 
+  /**
+   * This method opens the Excel file, initializes the Streaming Excel Reader, and initializes the sheet variable.
+   * @param negotiator The Drill file negotiator object that represents the file system
+   */
   private void openFile(FileScanFramework.FileSchemaNegotiator negotiator) {
     try {
       fsStream = negotiator.fileSystem().openPossiblyCompressedStream(split.getPath());
-      workbook = new XSSFWorkbook(fsStream);
+
+      // Open streaming reader
+      workbook = StreamingReader.builder()
+        .rowCacheSize(ROW_CACHE_SIZE)
+        .bufferSize(BUFFER_SIZE)
+        .open(fsStream);
     } catch (Exception e) {
       throw UserException
         .dataReadError(e)
         .message("Failed to open open input file: %s", split.getPath().toString())
-        .message(e.getMessage())
+        .addContext(e.getMessage())
         .build(logger);
     }
-
-    // Evaluate formulae
-    evaluator = workbook.getCreationHelper().createFormulaEvaluator();
-
-    workbook.setMissingCellPolicy(Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
     sheet = getSheet();
   }
 
   /**
    * This function defines the schema from the header row.
-   * @return TupleMedata of the discovered schema
    */
-  private TupleMetadata defineSchema() {
+  private void defineSchema() {
     SchemaBuilder builder = new SchemaBuilder();
-    return getColumnHeaders(builder);
+    getColumnHeaders(builder);
   }
 
-  private TupleMetadata getColumnHeaders(SchemaBuilder builder) {
+  private void getColumnHeaders(SchemaBuilder builder) {
     //Get the field names
-    int columnCount = 0;
+    int columnCount;
 
-    // Case for empty sheet.
-    if (sheet.getFirstRowNum() == 0 && sheet.getLastRowNum() == 0) {
-      return builder.buildSchema();
+    // Case for empty sheet
+    if (sheet.getLastRowNum() == 0) {
+      builder.buildSchema();
+      return;
     }
 
+    rowIterator = sheet.iterator();
+
     // Get the number of columns.
     columnCount = getColumnCount();
 
-    excelFieldNames = new ArrayList<>(columnCount);
-    cellWriterArray = new ArrayList<>(columnCount);
-    rowIterator = sheet.iterator();
+    excelFieldNames = new ArrayList<>();
+    cellWriterArray = new ArrayList<>();
 
     //If there are no headers, create columns names of field_n
     if (readerConfig.headerRow == -1) {
       String missingFieldName;
-      for (int i = 0; i < columnCount; i++) {
+      int i = 0;
+
+      for(Cell c : currentRow) {
 
 Review comment:
   ```suggestion
         for (Cell c : currentRow) {
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services