You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/04/26 19:16:57 UTC

arrow git commit: ARROW-886 [Java] Fixing reallocation of VariableLengthVector offsets

Repository: arrow
Updated Branches:
  refs/heads/master 8bf61d168 -> 3fdeac74c


ARROW-886 [Java] Fixing reallocation of VariableLengthVector offsets

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

Closes #591 from elahrvivaz/ARROW-886 and squashes the following commits:

5f6b4be [Emilio Lahr-Vivaz] ARROW-886 Fixing reallocation of VariableLengthVector offsets


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

Branch: refs/heads/master
Commit: 3fdeac74c80593ebde7a8eeb148cea9f6e0d1b38
Parents: 8bf61d1
Author: Emilio Lahr-Vivaz <el...@ccri.com>
Authored: Wed Apr 26 15:16:53 2017 -0400
Committer: Wes McKinney <we...@twosigma.com>
Committed: Wed Apr 26 15:16:53 2017 -0400

----------------------------------------------------------------------
 .../templates/VariableLengthVectors.java        |  1 +
 .../apache/arrow/vector/TestVectorReAlloc.java  | 27 +++++++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/3fdeac74/java/vector/src/main/codegen/templates/VariableLengthVectors.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/VariableLengthVectors.java b/java/vector/src/main/codegen/templates/VariableLengthVectors.java
index 4a460c5..11f0cc8 100644
--- a/java/vector/src/main/codegen/templates/VariableLengthVectors.java
+++ b/java/vector/src/main/codegen/templates/VariableLengthVectors.java
@@ -355,6 +355,7 @@ public final class ${minor.class}Vector extends BaseDataValueVector implements V
   }
 
   public void reAlloc() {
+    offsetVector.reAlloc();
     final long newAllocationSize = allocationSizeInBytes*2L;
     if (newAllocationSize > MAX_ALLOCATION_SIZE)  {
       throw new OversizedAllocationException("Unable to expand the buffer. Max allowed buffer size is reached.");

http://git-wip-us.apache.org/repos/asf/arrow/blob/3fdeac74/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReAlloc.java
----------------------------------------------------------------------
diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReAlloc.java b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReAlloc.java
index a7c35b6..40c7bc5 100644
--- a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReAlloc.java
+++ b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorReAlloc.java
@@ -73,6 +73,31 @@ public class TestVectorReAlloc {
   }
 
   @Test
+  public void testVariableLengthType() {
+    try (final VarCharVector vector = new VarCharVector("", allocator)) {
+      final VarCharVector.Mutator m = vector.getMutator();
+      // note: capacity ends up being - 1 due to offsets vector
+      vector.setInitialCapacity(511);
+      vector.allocateNew();
+
+      assertEquals(511, vector.getValueCapacity());
+
+      try {
+        m.set(512, "foo".getBytes(StandardCharsets.UTF_8));
+        Assert.fail("Expected out of bounds exception");
+      } catch (Exception e) {
+        // ok
+      }
+
+      vector.reAlloc();
+      assertEquals(1023, vector.getValueCapacity());
+
+      m.set(512, "foo".getBytes(StandardCharsets.UTF_8));
+      assertEquals("foo", new String(vector.getAccessor().get(512), StandardCharsets.UTF_8));
+    }
+  }
+
+  @Test
   public void testNullableType() {
     try (final NullableVarCharVector vector = new NullableVarCharVector("", allocator)) {
       final NullableVarCharVector.Mutator m = vector.getMutator();
@@ -89,7 +114,7 @@ public class TestVectorReAlloc {
       }
 
       vector.reAlloc();
-      assertEquals(1023, vector.getValueCapacity()); // note: size - 1 for some reason...
+      assertEquals(1024, vector.getValueCapacity());
 
       m.set(512, "foo".getBytes(StandardCharsets.UTF_8));
       assertEquals("foo", new String(vector.getAccessor().get(512), StandardCharsets.UTF_8));