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

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

paul-rogers commented on pull request #1899: DRILL-7445: Create batch copier 
based on result set framework
URL: https://github.com/apache/drill/pull/1899#discussion_r348110561
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/physical/resultSet/impl/ResultSetCopierImpl.java
 ##########
 @@ -0,0 +1,321 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.physical.resultSet.impl;
+
+import org.apache.drill.exec.memory.BufferAllocator;
+import org.apache.drill.exec.physical.impl.protocol.BatchAccessor;
+import org.apache.drill.exec.physical.resultSet.ResultSetCopier;
+import org.apache.drill.exec.physical.resultSet.ResultSetLoader;
+import org.apache.drill.exec.physical.resultSet.ResultSetReader;
+import org.apache.drill.exec.physical.resultSet.RowSetLoader;
+import org.apache.drill.exec.physical.rowSet.RowSetReader;
+import org.apache.drill.exec.record.VectorContainer;
+import org.apache.drill.exec.record.metadata.MetadataUtils;
+import org.apache.drill.exec.record.metadata.TupleMetadata;
+import org.apache.drill.exec.vector.accessor.ColumnReader;
+import org.apache.drill.exec.vector.accessor.ColumnWriter;
+import org.apache.drill.shaded.guava.com.google.common.base.Preconditions;
+
+public class ResultSetCopierImpl implements ResultSetCopier {
+
+  private enum State {
+    START,
+    NO_SCHEMA,
+    BETWEEN_BATCHES,
+    BATCH_ACTIVE,
+    NEW_SCHEMA,
+    SCHEMA_PENDING,
+    CLOSED
+  }
+
+  private interface BlockCopy {
+    void copy();
+    boolean hasMore();
+  }
+
+  private class CopyAll implements BlockCopy {
+
+    @Override
+    public void copy() {
+      while (!rowWriter.isFull() && rowReader.next()) {
+        project();
+      }
+    }
+
+    @Override
+    public boolean hasMore() {
+      return rowReader.hasNext();
+    }
+  }
+
+  private static class CopyPair {
+    protected final ColumnWriter writer;
+    protected final ColumnReader reader;
+
+    protected CopyPair(ColumnWriter writer, ColumnReader reader) {
+      this.writer = writer;
+      this.reader = reader;
+    }
+  }
+
+  // Input state
+
+  private int currentSchemaVersion = -1;
+  private final ResultSetReader resultSetReader;
+  protected RowSetReader rowReader;
+
+  // Output state
+
+  private final BufferAllocator allocator;
+  private final OptionBuilder writerOptions;
+  private ResultSetLoader resultSetWriter;
+  private RowSetLoader rowWriter;
+
+  // Copy state
+
+  private State state;
+  private CopyPair[] projection;
+  private BlockCopy activeCopy;
+
+  public ResultSetCopierImpl(BufferAllocator allocator, BatchAccessor 
inputBatch) {
+    this(allocator, inputBatch, new OptionBuilder());
+  }
+
+  public ResultSetCopierImpl(BufferAllocator allocator, BatchAccessor 
inputBatch,
+      OptionBuilder outputOptions) {
+    this.allocator = allocator;
+    resultSetReader = new ResultSetReaderImpl(inputBatch);
+    writerOptions = outputOptions;
+    writerOptions.setVectorCache(new ResultVectorCacheImpl(allocator));
+    state = State.START;
 
 Review comment:
   See above about use of `this.` prefix.
 
----------------------------------------------------------------
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


> Create batch copier based on result set framework
> -------------------------------------------------
>
>                 Key: DRILL-7445
>                 URL: https://issues.apache.org/jira/browse/DRILL-7445
>             Project: Apache Drill
>          Issue Type: Improvement
>    Affects Versions: 1.16.0
>            Reporter: Paul Rogers
>            Assignee: Paul Rogers
>            Priority: Minor
>             Fix For: 1.17.0
>
>
> The result set framework now provides both a reader and writer. Provide a 
> copier that copies batches using this framework. Such a copier can:
> * Copy selected records
> * Copy all records, such as for an SV2 or SV4



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

Reply via email to