You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by pr...@apache.org on 2019/08/24 10:13:27 UTC

[arrow] branch master updated: ARROW-6343: [Java][Vector] Fix allocation helper.

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

praveenbingo 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 e971567  ARROW-6343: [Java][Vector] Fix allocation helper.
e971567 is described below

commit e971567431d2a603480b1e407d297b1c2bc2a759
Author: Praveen <pr...@dremio.com>
AuthorDate: Sat Aug 24 15:43:10 2019 +0530

    ARROW-6343: [Java][Vector] Fix allocation helper.
    
    - Allocation helper not passing value count when
      creating varchar vectors.
    
    Closes #5186 from praveenbingo/ARROW-6343 and squashes the following commits:
    
    95706c690 <Praveen> ARROW-6343:  Fix allocation helper.
    
    Authored-by: Praveen <pr...@dremio.com>
    Signed-off-by: Praveen <pr...@dremio.com>
---
 .../main/java/org/apache/arrow/vector/AllocationHelper.java |  2 ++
 .../java/org/apache/arrow/vector/TestVectorReAlloc.java     | 13 +++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/java/vector/src/main/java/org/apache/arrow/vector/AllocationHelper.java b/java/vector/src/main/java/org/apache/arrow/vector/AllocationHelper.java
index 60bf028..af4654c 100644
--- a/java/vector/src/main/java/org/apache/arrow/vector/AllocationHelper.java
+++ b/java/vector/src/main/java/org/apache/arrow/vector/AllocationHelper.java
@@ -86,6 +86,8 @@ public class AllocationHelper {
   public static void allocateNew(ValueVector v, int valueCount) {
     if (v instanceof FixedWidthVector) {
       ((FixedWidthVector) v).allocateNew(valueCount);
+    } else if (v instanceof VariableWidthVector) {
+      ((VariableWidthVector) v).allocateNew(valueCount);
     } else {
       v.allocateNew();
     }
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 39132c2..198286f 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
@@ -204,6 +204,19 @@ public class TestVectorReAlloc {
   }
 
   @Test
+  public void testVarCharAllocateNewUsingHelper() throws Exception {
+    final int count = 6000;
+
+    try (final VarCharVector vector = new VarCharVector("", allocator)) {
+      AllocationHelper.allocateNew(vector, count);
+
+      // verify that the validity buffer and value buffer have capacity for atleast 'count' elements.
+      Assert.assertTrue(vector.getValidityBuffer().capacity() >= DataSizeRoundingUtil.divideBy8Ceil(count));
+      Assert.assertTrue(vector.getOffsetBuffer().capacity() >= (count + 1) * VarCharVector.OFFSET_WIDTH);
+    }
+  }
+
+  @Test
   public void testFixedRepeatedClearAndSet() throws Exception {
     try (final IntVector vector = new IntVector("", allocator)) {
       vector.allocateNewSafe(); // Initial allocation