This is an automated email from the ASF dual-hosted git repository.

ravindra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 6eae790  ARROW-6143: [Java] Unify the copyFrom and copyFromSafe 
methods for all vectors
6eae790 is described below

commit 6eae79000336788925fab1f1c011146e24c4838d
Author: liyafan82 <fan_li...@foxmail.com>
AuthorDate: Wed Aug 14 14:52:00 2019 +0530

    ARROW-6143: [Java] Unify the copyFrom and copyFromSafe methods for all 
vectors
    
    Some vectors have their own implementations of copyFrom and copyFromSafe 
methods.
    
    Since we have extracted the copyFrom and copyFromSafe methods to the base 
interface (see ARROW-6021), we want all vectors' implementations to override 
the methods from the super interface.
    
    This will provide a unified way of copying data elements.
    
    Closes #5019 from liyafan82/fly_0806_copy and squashes the following 
commits:
    
    116d746ce <liyafan82>  Unify the copyFrom and copyFromSafe methods for all 
vectors
    
    Authored-by: liyafan82 <fan_li...@foxmail.com>
    Signed-off-by: Pindikura Ravindra <ravin...@dremio.com>
---
 java/vector/src/main/codegen/templates/UnionVector.java          | 2 ++
 .../main/java/org/apache/arrow/vector/BaseFixedWidthVector.java  | 2 ++
 .../java/org/apache/arrow/vector/BaseVariableWidthVector.java    | 2 ++
 .../org/apache/arrow/vector/complex/FixedSizeListVector.java     | 7 +++++--
 .../main/java/org/apache/arrow/vector/complex/ListVector.java    | 9 ++++++---
 .../org/apache/arrow/vector/complex/NonNullableStructVector.java | 9 ++++++++-
 6 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/java/vector/src/main/codegen/templates/UnionVector.java 
b/java/vector/src/main/codegen/templates/UnionVector.java
index 6220e51..70eaee7 100644
--- a/java/vector/src/main/codegen/templates/UnionVector.java
+++ b/java/vector/src/main/codegen/templates/UnionVector.java
@@ -45,6 +45,7 @@ import org.apache.arrow.vector.ipc.message.ArrowFieldNode;
 import org.apache.arrow.memory.BaseAllocator;
 import org.apache.arrow.vector.BaseValueVector;
 import org.apache.arrow.vector.util.OversizedAllocationException;
+import org.apache.arrow.util.Preconditions;
 
 import static org.apache.arrow.vector.types.UnionMode.Sparse;
 
@@ -390,6 +391,7 @@ public class UnionVector implements FieldVector {
 
   @Override
   public void copyFrom(int inIndex, int outIndex, ValueVector from) {
+    Preconditions.checkArgument(this.getMinorType() == from.getMinorType());
     UnionVector fromCast = (UnionVector) from;
     fromCast.getReader().setPosition(inIndex);
     getWriter().setPosition(outIndex);
diff --git 
a/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java 
b/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java
index a166373..90f8898 100644
--- 
a/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java
+++ 
b/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java
@@ -822,6 +822,7 @@ public abstract class BaseFixedWidthVector extends 
BaseValueVector
    * @param thisIndex position to copy to in this vector
    * @param from      source vector
    */
+  @Override
   public void copyFrom(int fromIndex, int thisIndex, ValueVector from) {
     Preconditions.checkArgument(this.getMinorType() == from.getMinorType());
     if (from.isNull(fromIndex)) {
@@ -842,6 +843,7 @@ public abstract class BaseFixedWidthVector extends 
BaseValueVector
    * @param thisIndex position to copy to in this vector
    * @param from      source vector
    */
+  @Override
   public void copyFromSafe(int fromIndex, int thisIndex, ValueVector from) {
     Preconditions.checkArgument(this.getMinorType() == from.getMinorType());
     handleSafe(thisIndex);
diff --git 
a/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java
 
b/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java
index b7aa816..dedb29a 100644
--- 
a/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java
+++ 
b/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java
@@ -1290,6 +1290,7 @@ public abstract class BaseVariableWidthVector extends 
BaseValueVector
    * @param thisIndex position to copy to in this vector
    * @param from source vector
    */
+  @Override
   public void copyFrom(int fromIndex, int thisIndex, ValueVector from) {
     Preconditions.checkArgument(this.getMinorType() == from.getMinorType());
     if (from.isNull(fromIndex)) {
@@ -1319,6 +1320,7 @@ public abstract class BaseVariableWidthVector extends 
BaseValueVector
    * @param thisIndex position to copy to in this vector
    * @param from source vector
    */
+  @Override
   public void copyFromSafe(int fromIndex, int thisIndex, ValueVector from) {
     Preconditions.checkArgument(this.getMinorType() == from.getMinorType());
     if (from.isNull(fromIndex)) {
diff --git 
a/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java
 
b/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java
index 6bdf817..bdd0f57 100644
--- 
a/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java
+++ 
b/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java
@@ -386,11 +386,14 @@ public class FixedSizeListVector extends BaseValueVector 
implements FieldVector,
     return new AddOrGetResult<>((T) vector, created);
   }
 
-  public void copyFromSafe(int inIndex, int outIndex, FixedSizeListVector 
from) {
+  @Override
+  public void copyFromSafe(int inIndex, int outIndex, ValueVector from) {
     copyFrom(inIndex, outIndex, from);
   }
 
-  public void copyFrom(int fromIndex, int thisIndex, FixedSizeListVector from) 
{
+  @Override
+  public void copyFrom(int fromIndex, int thisIndex, ValueVector from) {
+    Preconditions.checkArgument(this.getMinorType() == from.getMinorType());
     TransferPair pair = from.makeTransferPair(this);
     pair.copyValueSafe(fromIndex, thisIndex);
   }
diff --git 
a/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java 
b/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java
index d6935de..e0913b5 100644
--- a/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java
+++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java
@@ -333,14 +333,15 @@ public class ListVector extends BaseRepeatedValueVector 
implements FieldVector,
   }
 
   /**
-   * Same as {@link #copyFrom(int, int, ListVector)} except that
+   * Same as {@link #copyFrom(int, int, ValueVector)} except that
    * it handles the case when the capacity of the vector needs to be expanded
    * before copy.
    * @param inIndex position to copy from in source vector
    * @param outIndex position to copy to in this vector
    * @param from source vector
    */
-  public void copyFromSafe(int inIndex, int outIndex, ListVector from) {
+  @Override
+  public void copyFromSafe(int inIndex, int outIndex, ValueVector from) {
     copyFrom(inIndex, outIndex, from);
   }
 
@@ -351,7 +352,9 @@ public class ListVector extends BaseRepeatedValueVector 
implements FieldVector,
    * @param outIndex position to copy to in this vector
    * @param from source vector
    */
-  public void copyFrom(int inIndex, int outIndex, ListVector from) {
+  @Override
+  public void copyFrom(int inIndex, int outIndex, ValueVector from) {
+    Preconditions.checkArgument(this.getMinorType() == from.getMinorType());
     FieldReader in = from.getReader();
     in.setPosition(inIndex);
     FieldWriter out = getWriter();
diff --git 
a/java/vector/src/main/java/org/apache/arrow/vector/complex/NonNullableStructVector.java
 
b/java/vector/src/main/java/org/apache/arrow/vector/complex/NonNullableStructVector.java
index 995751e..c7e4f2c 100644
--- 
a/java/vector/src/main/java/org/apache/arrow/vector/complex/NonNullableStructVector.java
+++ 
b/java/vector/src/main/java/org/apache/arrow/vector/complex/NonNullableStructVector.java
@@ -92,7 +92,9 @@ public class NonNullableStructVector extends 
AbstractStructVector {
    * Copies the element at fromIndex in the provided vector to thisIndex.  
Reallocates buffers
    * if thisIndex is larger then current capacity.
    */
-  public void copyFromSafe(int fromIndex, int thisIndex, 
NonNullableStructVector from) {
+  @Override
+  public void copyFrom(int fromIndex, int thisIndex, ValueVector from) {
+    Preconditions.checkArgument(this.getMinorType() == from.getMinorType());
     if (ephPair == null || ephPair.from != from) {
       ephPair = (StructTransferPair) from.makeTransferPair(this);
     }
@@ -100,6 +102,11 @@ public class NonNullableStructVector extends 
AbstractStructVector {
   }
 
   @Override
+  public void copyFromSafe(int fromIndex, int thisIndex, ValueVector from) {
+    copyFrom(fromIndex, thisIndex, from);
+  }
+
+  @Override
   protected boolean supportsDirectRead() {
     return true;
   }

Reply via email to