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/05/23 20:48:43 UTC

[GitHub] [drill] sanel commented on a change in pull request #2069: DRILL-7723 - Add Excel Metadata as Implicit Fields

sanel commented on a change in pull request #2069:
URL: https://github.com/apache/drill/pull/2069#discussion_r429577212



##########
File path: contrib/format-excel/src/main/java/org/apache/drill/exec/store/excel/ExcelBatchReader.java
##########
@@ -420,15 +510,57 @@ private void addColumnToArray(TupleWriter rowWriter, String name, TypeProtos.Min
     }
   }
 
+  private void addMetadataWriters() {
+    for (String colName : IMPLICIT_STRING_COLUMN_NAMES) {
+      addMetadataColumnsToArray(rowWriter, colName, MinorType.VARCHAR);
+    }
+    for (String colName : IMPLICIT_TIMESTAMP_COLUMN_NAMES) {
+      addMetadataColumnsToArray(rowWriter, colName, MinorType.TIMESTAMP);
+    }
+  }
+
+  private void addMetadataColumnsToArray(TupleWriter rowWriter, String name, MinorType type) {
+    int index = rowWriter.tupleSchema().index(name);
+    if (index == -1) {
+      ColumnMetadata colSchema = MetadataUtils.newScalar(name, type, TypeProtos.DataMode.OPTIONAL);
+      colSchema.setBooleanProperty(ColumnMetadata.EXCLUDE_FROM_WILDCARD, true);
+      index = rowWriter.addColumn(colSchema);
+    } else {
+      return;
+    }
+    metadataColumnWriters.add(rowWriter.scalar(index));
+  }
+
+  private void writeMetadata() {
+    for (int i = 0; i < metadataColumnWriters.size(); i++) {
+      if (i < IMPLICIT_STRING_COLUMN_NAMES.size()) {

Review comment:
       Why just don't say something like:
   
   ```java
   int n = i - IMPLICIT_STRING_COLUMN_NAMES.size();
   if (n < 0) {
    ...
   } else {
    ...
    ... = dateMetadata.get(IMPLICIT_TIMESTAMP_COLUMN_NAMES.get(n);
   ...
   }
   ```




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