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

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

arina-ielchiieva commented on 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


> Convert the regex ("log") plugin to use EVF
> -------------------------------------------
>
>                 Key: DRILL-7293
>                 URL: https://issues.apache.org/jira/browse/DRILL-7293
>             Project: Apache Drill
>          Issue Type: Improvement
>    Affects Versions: 1.16.0
>            Reporter: Paul Rogers
>            Assignee: Paul Rogers
>            Priority: Major
>             Fix For: 1.17.0
>
>
> The "log" plugin (which uses a regex to define the row format) is the subject 
> of Chapter 12 of the Learning Apache Drill book (though the version in the 
> book is simpler than the one in the master branch.)
> The recently-completed "Enhanced Vector Framework" (EVF, AKA the "row set 
> framework") gives Drill control over the size of batches created by readers, 
> and allows readers to use the recently-added provided schema mechanism.
> We wish to use the log reader as an example for how to convert a Drill format 
> plugin to use the EVF so that other developers can convert their own plugins.
> This PR provides the first set of log plugin changes to enable us to publish 
> a tutorial on the EVF.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to