[ 
https://issues.apache.org/jira/browse/DRILL-7912?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17338051#comment-17338051
 ] 

ASF GitHub Bot commented on DRILL-7912:
---------------------------------------

cgivre commented on a change in pull request #2211:
URL: https://github.com/apache/drill/pull/2211#discussion_r624710325



##########
File path: 
contrib/format-excel/src/main/java/org/apache/drill/exec/store/excel/ExcelBatchReader.java
##########
@@ -566,6 +598,34 @@ private void writeMetadata() {
         
metadataColumnWriters.get(index).setTimestamp(Instant.ofEpochMilli(timeValue.getTime()));
       }
     }
+
+    // Write the sheet names.  Since this is the only list field
+    int listIndex = IMPLICIT_STRING_COLUMN.values().length + 
IMPLICIT_TIMESTAMP_COLUMN.values().length;
+    String sheetColumnName = IMPLICIT_LIST_COLUMN.SHEETS.fieldName;
+    List<String> sheetNames = listMetadata.get(sheetColumnName);
+
+    if (sheetNameWriter == null) {
+      int sheetColumnIndex = 
rowWriter.tupleSchema().index(IMPLICIT_LIST_COLUMN.SHEETS.getFieldName());
+      if (sheetColumnIndex == -1) {
+        ColumnMetadata colSchema = MetadataUtils.newScalar(sheetColumnName, 
MinorType.VARCHAR, DataMode.REPEATED);
+        colSchema.setBooleanProperty(ColumnMetadata.EXCLUDE_FROM_WILDCARD, 
true);
+        listIndex = rowWriter.addColumn(colSchema);
+      }
+      sheetNameWriter = rowWriter.column(listIndex).array().scalar();
+    }
+
+    for (String sheetName : sheetNames) {
+      sheetNameWriter.setString(sheetName);
+    }
+  }
+
+  private List<String> getSheetNames() {
+    List<String> sheets = new ArrayList<>();
+    int sheetCount = streamingWorkbook.getNumberOfSheets();
+    for (int i = 0; i < sheetCount; i++) {
+      sheets.add(streamingWorkbook.getSheetName(i));

Review comment:
       Excel populates the names by default as `Sheet 1` etc.  I don't think 
Excel will let you have a `null` name, and if it is blank you'd just get `""` 
which will work. 




-- 
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:
[email protected]


> Add Sheet Names to Excel Reader
> -------------------------------
>
>                 Key: DRILL-7912
>                 URL: https://issues.apache.org/jira/browse/DRILL-7912
>             Project: Apache Drill
>          Issue Type: Improvement
>          Components: Storage - Other
>    Affects Versions: 1.18.0
>            Reporter: Charles Givre
>            Assignee: Charles Givre
>            Priority: Major
>             Fix For: 1.19.0
>
>
> Currently, there is no way to determine what sheets are available in an Excel 
> file.  This PR adds a metadata field called `_sheets` which a user can query 
> to determine available sheets in a given file. 



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

Reply via email to