arina-ielchiieva commented on a change in pull request #1807: DRILL-7293: 
Convert the regex ("log") plugin to use EVF
URL: https://github.com/apache/drill/pull/1807#discussion_r301667671
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/log/LogBatchReader.java
 ##########
 @@ -43,60 +44,135 @@
   public static final String RAW_LINE_COL_NAME = "_raw";
   public static final String UNMATCHED_LINE_COL_NAME = "_unmatched_rows";
 
-  private final LogFormatConfig formatConfig;
-  private final Pattern pattern;
-  private final TupleMetadata schema;
-  private final int maxErrors;
+  public static class LogReaderConfig {
+    protected final LogFormatPlugin plugin;
+    protected final Pattern pattern;
+    protected final TupleMetadata schema;
+    protected final boolean asArray;
+    protected final int groupCount;
+    protected final int maxErrors;
+
+    public LogReaderConfig(LogFormatPlugin plugin, Pattern pattern,
+        TupleMetadata schema, boolean asArray,
+        int groupCount, int maxErrors) {
+      this.plugin = plugin;
+      this.pattern = pattern;
+      this.schema = schema;
+      this.asArray = asArray;
+      this.groupCount = groupCount;
+      this.maxErrors = maxErrors;
+    }
+  }
+
+  /**
+   * Write group values to value vectors.
+   */
+
+  private interface VectorWriter {
+    void loadVectors(Matcher m);
+  }
+
+  /**
+   * Write group values to individual scalar columns.
+   */
+
+  private static class ScalarGroupWriter implements VectorWriter {
+
+    private final TupleWriter rowWriter;
+
+    public ScalarGroupWriter(TupleWriter rowWriter) {
+      this.rowWriter = rowWriter;
+    }
+
+    @Override
+    public void loadVectors(Matcher m) {
+      for (int i = 0; i < m.groupCount(); i++) {
+        String value = m.group(i + 1);
+        if (value != null) {
+          rowWriter.scalar(i).setString(value);
+        }
+      }
+    }
+  }
+
+  /**
+   * Write group values to the columns[] array.
+   */
+
+  private static class ColumnsArrayWriter implements VectorWriter {
+
+    private final ScalarWriter elementWriter;
+
+    public ColumnsArrayWriter(TupleWriter rowWriter) {
+      elementWriter = rowWriter.array(0).scalar();
+    }
+
+   @Override
+    public void loadVectors(Matcher m) {
+      for (int i = 0; i < m.groupCount(); i++) {
+        String value = m.group(i + 1);
+        elementWriter.setString(value == null ? "" : value);
+      }
+    }
+  }
+
+  private final LogReaderConfig config;
   private FileSplit split;
   private BufferedReader reader;
-  private int capturingGroups;
   private ResultSetLoader loader;
+  private VectorWriter vectorWriter;
   private ScalarWriter rawColWriter;
   private ScalarWriter unmatchedColWriter;
   private boolean saveMatchedRows;
   private int lineNumber;
   private int errorCount;
 
-  public LogBatchReader(LogFormatConfig formatConfig, Pattern pattern,
-      TupleMetadata schema, int maxErrors) {
-    this.formatConfig = formatConfig;
-    this.pattern = pattern;
-    this.schema = schema;
-    this.maxErrors = maxErrors;
+  public LogBatchReader(LogReaderConfig config) {
+    this.config = config;
   }
 
   @Override
   public boolean open(FileSchemaNegotiator negotiator) {
     split = negotiator.split();
-    setupPattern();
-    negotiator.setTableSchema(schema, true);
+    negotiator.setTableSchema(config.schema, true);
     loader = negotiator.build();
     bindColumns(loader.writer());
     openFile(negotiator);
     return true;
   }
 
-  private void setupPattern() {
-    // Turns out the only way to learn the capturing group count
-    // is to create a matcher. We do so with a dummy string.
-
-    Matcher m = pattern.matcher("dummy");
-    capturingGroups = m.groupCount();
-  }
-
   private void bindColumns(RowSetLoader writer) {
-    for (int i = 0; i < capturingGroups; i++) {
-      saveMatchedRows |= writer.scalar(i).isProjected();
-    }
     rawColWriter = writer.scalar(RAW_LINE_COL_NAME);
-    saveMatchedRows |= rawColWriter.isProjected();
     unmatchedColWriter = writer.scalar(UNMATCHED_LINE_COL_NAME);
+    saveMatchedRows = rawColWriter.isProjected();
 
     // If no match-case columns are projected, and the unmatched
     // columns is unprojected, then we want to count (matched)
     // rows.
 
     saveMatchedRows |= !unmatchedColWriter.isProjected();
+
+    // This reader is unusual: it can save only unmatched rows,
 
 Review comment:
   Not quite sure I understand meaning of such reader.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to