arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jul...@apache.org
Subject arrow git commit: ARROW-403: [Java] Create transfer pairs for internal vectors in UnionVector transfer impl
Date Tue, 06 Dec 2016 05:28:19 GMT
Repository: arrow
Updated Branches:
  refs/heads/master 599d516a7 -> 82575ca3c


ARROW-403: [Java] Create transfer pairs for internal vectors in UnionVector transfer impl

@StevenMPhillips, @julienledem Could you please review the patch?

Author: vkorukanti <venki@dremio.com>

Closes #225 from vkorukanti/union_vector_schema and squashes the following commits:

431874f [vkorukanti] ARROW-403: [Java] Create transfer pairs for internal vectors in UnionVector
transfer impl


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/82575ca3
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/82575ca3
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/82575ca3

Branch: refs/heads/master
Commit: 82575ca3c22db18b2ea69f248b471a0317042b38
Parents: 599d516
Author: vkorukanti <venki@dremio.com>
Authored: Mon Dec 5 21:28:14 2016 -0800
Committer: Julien Le Dem <julien@dremio.com>
Committed: Mon Dec 5 21:28:14 2016 -0800

----------------------------------------------------------------------
 .../src/main/codegen/templates/UnionVector.java | 19 +++----
 .../apache/arrow/vector/TestUnionVector.java    | 54 ++++++++++++++++++++
 2 files changed, 64 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/82575ca3/java/vector/src/main/codegen/templates/UnionVector.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/UnionVector.java b/java/vector/src/main/codegen/templates/UnionVector.java
index ea1fdf6..4e68b68 100644
--- a/java/vector/src/main/codegen/templates/UnionVector.java
+++ b/java/vector/src/main/codegen/templates/UnionVector.java
@@ -246,12 +246,6 @@ public class UnionVector implements FieldVector {
     return new TransferImpl((UnionVector) target);
   }
 
-  public void transferTo(org.apache.arrow.vector.complex.UnionVector target) {
-    typeVector.makeTransferPair(target.typeVector).transfer();
-    internalMap.makeTransferPair(target.internalMap).transfer();
-    target.valueCount = valueCount;
-  }
-
   public void copyFrom(int inIndex, int outIndex, UnionVector from) {
     from.getReader().setPosition(inIndex);
     getWriter().setPosition(outIndex);
@@ -275,20 +269,27 @@ public class UnionVector implements FieldVector {
   }
 
   private class TransferImpl implements TransferPair {
-
-    UnionVector to;
+    private final TransferPair internalMapVectorTransferPair;
+    private final TransferPair typeVectorTransferPair;
+    private final UnionVector to;
 
     public TransferImpl(String name, BufferAllocator allocator) {
       to = new UnionVector(name, allocator, null);
+      internalMapVectorTransferPair = internalMap.makeTransferPair(to.internalMap);
+      typeVectorTransferPair = typeVector.makeTransferPair(to.typeVector);
     }
 
     public TransferImpl(UnionVector to) {
       this.to = to;
+      internalMapVectorTransferPair = internalMap.makeTransferPair(to.internalMap);
+      typeVectorTransferPair = typeVector.makeTransferPair(to.typeVector);
     }
 
     @Override
     public void transfer() {
-      transferTo(to);
+      internalMapVectorTransferPair.transfer();
+      typeVectorTransferPair.transfer();
+      to.valueCount = valueCount;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/arrow/blob/82575ca3/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java
----------------------------------------------------------------------
diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java
index 1bb50b7..a5b90ee 100644
--- a/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java
+++ b/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java
@@ -21,8 +21,12 @@ import static org.junit.Assert.assertEquals;
 
 import org.apache.arrow.memory.BufferAllocator;
 import org.apache.arrow.vector.complex.UnionVector;
+import org.apache.arrow.vector.holders.NullableBitHolder;
+import org.apache.arrow.vector.holders.NullableIntHolder;
 import org.apache.arrow.vector.holders.NullableUInt4Holder;
 import org.apache.arrow.vector.types.Types;
+import org.apache.arrow.vector.types.Types.MinorType;
+import org.apache.arrow.vector.util.TransferPair;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -76,4 +80,54 @@ public class TestUnionVector {
     }
   }
 
+  @Test
+  public void testTransfer() throws Exception {
+    try (UnionVector srcVector = new UnionVector(EMPTY_SCHEMA_PATH, allocator, null)) {
+      srcVector.allocateNew();
+
+      // write some data
+      final UnionVector.Mutator mutator = srcVector.getMutator();
+      mutator.setType(0, MinorType.INT);
+      mutator.setSafe(0, newIntHolder(5));
+      mutator.setType(1, MinorType.BIT);
+      mutator.setSafe(1, newBitHolder(false));
+      mutator.setType(3, MinorType.INT);
+      mutator.setSafe(3, newIntHolder(10));
+      mutator.setType(5, MinorType.BIT);
+      mutator.setSafe(5, newBitHolder(false));
+      mutator.setValueCount(6);
+
+      try(UnionVector destVector = new UnionVector(EMPTY_SCHEMA_PATH, allocator, null)) {
+        TransferPair pair = srcVector.makeTransferPair(destVector);
+
+        // Creating the transfer should transfer the type of the field at least.
+        assertEquals(srcVector.getField(), destVector.getField());
+
+        // transfer
+        pair.transfer();
+
+        assertEquals(srcVector.getField(), destVector.getField());
+
+        // now check the values are transferred
+        assertEquals(srcVector.getAccessor().getValueCount(), destVector.getAccessor().getValueCount());
+        for(int i=0; i<srcVector.getAccessor().getValueCount(); i++) {
+          assertEquals("Different values at index " + i, srcVector.getAccessor().get(i),
destVector.getAccessor().get(i));
+        }
+      }
+    }
+  }
+
+  private static NullableIntHolder newIntHolder(int value) {
+    final NullableIntHolder holder = new NullableIntHolder();
+    holder.isSet = 1;
+    holder.value = value;
+    return holder;
+  }
+
+  private static NullableBitHolder newBitHolder(boolean value) {
+    final NullableBitHolder holder = new NullableBitHolder();
+    holder.isSet = 1;
+    holder.value = value ? 1 : 0;
+    return holder;
+  }
 }


Mime
View raw message