arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject arrow git commit: ARROW-997: [Java] Implementing transferPair for FixedSizeListVector
Date Wed, 17 May 2017 15:52:02 GMT
Repository: arrow
Updated Branches:
  refs/heads/master bed019743 -> c4086febd


ARROW-997: [Java] Implementing transferPair for FixedSizeListVector

Author: Emilio Lahr-Vivaz <elahrvivaz@ccri.com>

Closes #672 from elahrvivaz/ARROW-997 and squashes the following commits:

68be6a56 [Emilio Lahr-Vivaz] ARROW-997: [Java] Implementing transferPair for FixedSizeListVector


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

Branch: refs/heads/master
Commit: c4086febd2d2ce976100d6e65029a7b213583b39
Parents: bed0197
Author: Emilio Lahr-Vivaz <elahrvivaz@ccri.com>
Authored: Wed May 17 11:51:57 2017 -0400
Committer: Wes McKinney <wes.mckinney@twosigma.com>
Committed: Wed May 17 11:51:57 2017 -0400

----------------------------------------------------------------------
 .../vector/complex/FixedSizeListVector.java     | 16 +++--
 .../arrow/vector/TestFixedSizeListVector.java   | 66 ++++++++++++++++++++
 2 files changed, 77 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/c4086feb/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java
----------------------------------------------------------------------
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 ee22fbe..b6d938f 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
@@ -259,7 +259,7 @@ public class FixedSizeListVector extends BaseValueVector implements FieldVector,
   @SuppressWarnings("unchecked")
   public <T extends ValueVector> AddOrGetResult<T> addOrGetVector(FieldType type)
{
     boolean created = false;
-    if (vector instanceof ZeroVector) {
+    if (vector == ZeroVector.INSTANCE) {
       vector = type.createNewSingleVector(DATA_VECTOR_NAME, allocator, null);
       this.reader = new UnionFixedSizeListReader(this);
       created = true;
@@ -278,8 +278,9 @@ public class FixedSizeListVector extends BaseValueVector implements FieldVector,
     copyFrom(inIndex, outIndex, from);
   }
 
-  public void copyFrom(int inIndex, int outIndex, FixedSizeListVector from) {
-    throw new UnsupportedOperationException("FixedSizeListVector.copyFrom");
+  public void copyFrom(int fromIndex, int thisIndex, FixedSizeListVector from) {
+    TransferPair pair = from.makeTransferPair(this);
+    pair.copyValueSafe(fromIndex, thisIndex);
   }
 
   @Override
@@ -367,7 +368,7 @@ public class FixedSizeListVector extends BaseValueVector implements FieldVector,
       this.to = to;
       to.addOrGetVector(vector.getField().getFieldType());
       pairs[0] = bits.makeTransferPair(to.bits);
-      pairs[1] = getDataVector().makeTransferPair(to.getDataVector());
+      pairs[1] = vector.makeTransferPair(to.vector);
     }
 
     @Override
@@ -392,7 +393,12 @@ public class FixedSizeListVector extends BaseValueVector implements FieldVector,
 
     @Override
     public void copyValueSafe(int from, int to) {
-      this.to.copyFrom(from, to, FixedSizeListVector.this);
+      pairs[0].copyValueSafe(from, to);
+      int fromOffset = from * listSize;
+      int toOffset = to * listSize;
+      for (int i = 0; i < listSize; i++) {
+        pairs[1].copyValueSafe(fromOffset + i, toOffset + i);
+      }
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/arrow/blob/c4086feb/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeListVector.java
----------------------------------------------------------------------
diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeListVector.java
b/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeListVector.java
index f35ab54..304db9d 100644
--- a/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeListVector.java
+++ b/java/vector/src/test/java/org/apache/arrow/vector/TestFixedSizeListVector.java
@@ -28,6 +28,7 @@ import org.apache.arrow.vector.complex.reader.FieldReader;
 import org.apache.arrow.vector.types.Types.MinorType;
 import org.apache.arrow.vector.types.pojo.ArrowType;
 import org.apache.arrow.vector.types.pojo.FieldType;
+import org.apache.arrow.vector.util.TransferPair;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -153,4 +154,69 @@ public class TestFixedSizeListVector {
       }
     }
   }
+
+  @Test
+  public void testTransferPair() {
+    try (FixedSizeListVector from = new FixedSizeListVector("from", allocator, 2, null, null);
+         FixedSizeListVector to = new FixedSizeListVector("to", allocator, 2, null, null))
{
+      NullableFloat4Vector nested = (NullableFloat4Vector) from.addOrGetVector(FieldType.nullable(MinorType.FLOAT4.getType())).getVector();
+      NullableFloat4Vector.Mutator mutator = nested.getMutator();
+      from.allocateNew();
+
+      for (int i = 0; i < 10; i++) {
+        if (i % 2 == 0) {
+          from.getMutator().setNotNull(i);
+          mutator.set(i * 2, i + 0.1f);
+          mutator.set(i * 2 + 1, i + 10.1f);
+        }
+      }
+      from.getMutator().setValueCount(10);
+
+      TransferPair pair = from.makeTransferPair(to);
+
+      pair.copyValueSafe(0, 1);
+      pair.copyValueSafe(2, 2);
+      to.copyFromSafe(4, 3, from);
+      to.getMutator().setValueCount(10);
+
+      UnionFixedSizeListReader reader = to.getReader();
+
+      reader.setPosition(0);
+      Assert.assertFalse(reader.isSet());
+      Assert.assertNull(reader.readObject());
+
+      reader.setPosition(1);
+      Assert.assertTrue(reader.isSet());
+      Assert.assertTrue(reader.next());
+      Assert.assertEquals(0.1f, reader.reader().readFloat(), 0.00001);
+      Assert.assertTrue(reader.next());
+      Assert.assertEquals(10.1f, reader.reader().readFloat(), 0.00001);
+      Assert.assertFalse(reader.next());
+      Assert.assertEquals(Lists.newArrayList(0.1f, 10.1f), reader.readObject());
+
+      reader.setPosition(2);
+      Assert.assertTrue(reader.isSet());
+      Assert.assertTrue(reader.next());
+      Assert.assertEquals(2.1f, reader.reader().readFloat(), 0.00001);
+      Assert.assertTrue(reader.next());
+      Assert.assertEquals(12.1f, reader.reader().readFloat(), 0.00001);
+      Assert.assertFalse(reader.next());
+      Assert.assertEquals(Lists.newArrayList(2.1f, 12.1f), reader.readObject());
+
+      reader.setPosition(3);
+      Assert.assertTrue(reader.isSet());
+      Assert.assertTrue(reader.next());
+      Assert.assertEquals(4.1f, reader.reader().readFloat(), 0.00001);
+      Assert.assertTrue(reader.next());
+      Assert.assertEquals(14.1f, reader.reader().readFloat(), 0.00001);
+      Assert.assertFalse(reader.next());
+      Assert.assertEquals(Lists.newArrayList(4.1f, 14.1f), reader.readObject());
+
+      for (int i = 4; i < 10; i++) {
+        reader.setPosition(i);
+        Assert.assertFalse(reader.isSet());
+        Assert.assertNull(reader.readObject());
+      }
+    }
+  }
 }


Mime
View raw message