arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject [1/3] arrow git commit: ARROW-1473: ValueVector new hierarchy prototype (implementation phase 1) [Forced Update!]
Date Sat, 14 Oct 2017 15:38:58 GMT
Repository: arrow
Updated Branches:
  refs/heads/java-vector-refactor 7f45d86d7 -> 60a2ebdfc (forced update)


http://git-wip-us.apache.org/repos/asf/arrow/blob/60a2ebdf/java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java
----------------------------------------------------------------------
diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java
index a239861..b7f88c3 100644
--- a/java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java
+++ b/java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java
@@ -694,8 +694,6 @@ public class TestValueVector {
   public void testNullableFixedType3() {
     // Create a new value vector for 1024 integers
     try (final NullableIntVector vector = newVector(NullableIntVector.class, EMPTY_SCHEMA_PATH, MinorType.INT, allocator)) {
-      final NullableIntVector.Mutator mutator = vector.getMutator();
-      final NullableIntVector.Accessor accessor = vector.getAccessor();
       boolean error = false;
       int initialCapacity = 1024;
 
@@ -706,26 +704,26 @@ public class TestValueVector {
       /* underlying buffer should be able to store 16 values */
       assertEquals(initialCapacity, vector.getValueCapacity());
 
-      mutator.set(0, 1);
-      mutator.set(1, 2);
-      mutator.set(100, 3);
-      mutator.set(1022, 4);
-      mutator.set(1023, 5);
+      vector.set(0, 1);
+      vector.set(1, 2);
+      vector.set(100, 3);
+      vector.set(1022, 4);
+      vector.set(1023, 5);
 
       /* check vector contents */
       int j = 1;
       for(int i = 0; i <= 1023; i++) {
         if((i >= 2 && i <= 99) || (i >= 101 && i <= 1021)) {
-          assertTrue("non-null data not expected at index: " + i, accessor.isNull(i));
+          assertTrue("non-null data not expected at index: " + i, vector.isNull(i));
         }
         else {
-          assertFalse("null data not expected at index: " + i, accessor.isNull(i));
-          assertEquals("unexpected value at index: " + i, j, accessor.get(i));
+          assertFalse("null data not expected at index: " + i, vector.isNull(i));
+          assertEquals("unexpected value at index: " + i, j, vector.get(i));
           j++;
         }
       }
 
-      mutator.setValueCount(1024);
+      vector.setValueCount(1024);
       Field field = vector.getField();
       TypeLayout typeLayout = field.getTypeLayout();
 
@@ -749,7 +747,7 @@ public class TestValueVector {
       assertEquals(-64, validityVectorBuf.getByte(127)); // 1022nd and 1023rd bit defined
 
       /* this should trigger a realloc() */
-      mutator.setSafe(1024, 6);
+      vector.setSafe(1024, 6);
 
       /* underlying buffer should now be able to store double the number of values */
       assertEquals(initialCapacity * 2, vector.getValueCapacity());
@@ -758,11 +756,11 @@ public class TestValueVector {
       j = 1;
       for(int i = 0; i < (initialCapacity * 2); i++) {
         if((i > 1024) || (i >= 2 && i <= 99) || (i >= 101 && i <= 1021)) {
-          assertTrue("non-null data not expected at index: " + i, accessor.isNull(i));
+          assertTrue("non-null data not expected at index: " + i, vector.isNull(i));
         }
         else {
-          assertFalse("null data not expected at index: " + i, accessor.isNull(i));
-          assertEquals("unexpected value at index: " + i, j, accessor.get(i));
+          assertFalse("null data not expected at index: " + i, vector.isNull(i));
+          assertEquals("unexpected value at index: " + i, j, vector.get(i));
           j++;
         }
       }
@@ -775,13 +773,101 @@ public class TestValueVector {
 
       /* vector data should have been zeroed out */
       for(int i = 0; i < (initialCapacity * 2); i++) {
-        assertTrue("non-null data not expected at index: " + i, accessor.isNull(i));
+        assertTrue("non-null data not expected at index: " + i, vector.isNull(i));
       }
 
       vector.allocateNew(4096);
       // vector has been erased
       for(int i = 0; i < 4096; i++) {
-        assertTrue("non-null data not expected at index: " + i, accessor.isNull(i));
+        assertTrue("non-null data not expected at index: " + i, vector.isNull(i));
+      }
+    }
+  }
+
+  @Test /* NullableIntVector */
+  public void testNullableFixedType4() {
+    try (final NullableIntVector vector = newVector(NullableIntVector.class, EMPTY_SCHEMA_PATH, MinorType.INT, allocator)) {
+
+      /* no memory allocation has happened yet */
+      assertEquals(0, vector.getValueCapacity());
+
+      vector.allocateNew();
+      int valueCapacity = vector.getValueCapacity();
+      assertEquals(vector.INITIAL_VALUE_ALLOCATION, valueCapacity);
+
+      int baseValue = 20000;
+
+      for (int i = 0; i < valueCapacity; i++) {
+        if ((i & 1) == 1) {
+          vector.set(i, baseValue + i);
+        }
+      }
+
+      for (int i = 0; i < valueCapacity; i++) {
+        if ((i & 1) == 1) {
+          assertFalse("unexpected null value at index: " + i, vector.isNull(i));
+          assertEquals("unexpected value at index: " + i, (baseValue + i), vector.get(i));
+        } else {
+          assertTrue("unexpected non-null value at index: " + i, vector.isNull(i));
+        }
+      }
+
+      vector.setSafe(valueCapacity, 20000000);
+      assertEquals(valueCapacity * 2, vector.getValueCapacity());
+
+      for (int i = 0; i < vector.getValueCapacity(); i++) {
+        if (i == valueCapacity) {
+          assertFalse("unexpected null value at index: " + i, vector.isNull(i));
+          assertEquals("unexpected value at index: " + i, 20000000, vector.get(i));
+        } else if (i < valueCapacity) {
+          if ((i & 1) == 1) {
+            assertFalse("unexpected null value at index: " + i, vector.isNull(i));
+            assertEquals("unexpected value at index: " + i, (baseValue + i), vector.get(i));
+          }
+        } else {
+          assertTrue("unexpected non-null value at index: " + i, vector.isNull(i));
+        }
+      }
+
+      vector.zeroVector();
+
+      for (int i = 0; i < vector.getValueCapacity(); i+=2) {
+          vector.set(i, baseValue + i);
+      }
+
+      for (int i = 0; i < vector.getValueCapacity(); i++) {
+        if (i%2 == 0) {
+          assertFalse("unexpected null value at index: " + i, vector.isNull(i));
+          assertEquals("unexpected value at index: " + i, (baseValue + i), vector.get(i));
+        } else {
+          assertTrue("unexpected non-null value at index: " + i, vector.isNull(i));
+        }
+      }
+
+      vector.setSafe((valueCapacity *  2) + 1000, 400000000);
+      assertEquals(valueCapacity * 4, vector.getValueCapacity());
+
+      for (int i = 0; i < vector.getValueCapacity(); i++) {
+        if (i == (valueCapacity*2 + 1000)) {
+          assertFalse("unexpected null value at index: " + i, vector.isNull(i));
+          assertEquals("unexpected value at index: " + i, 400000000, vector.get(i));
+        } else if (i < valueCapacity*2 && (i%2) == 0) {
+          assertFalse("unexpected null value at index: " + i, vector.isNull(i));
+          assertEquals("unexpected value at index: " + i, baseValue + i, vector.get(i));
+        } else {
+          assertTrue("unexpected non-null value at index: " + i, vector.isNull(i));
+        }
+      }
+
+      /* reset the vector */
+      vector.reset();
+
+       /* capacity shouldn't change after reset */
+      assertEquals(valueCapacity * 4, vector.getValueCapacity());
+
+      /* vector data should be zeroed out */
+      for(int i = 0; i < (valueCapacity * 4); i++) {
+        assertTrue("non-null data not expected at index: " + i, vector.isNull(i));
       }
     }
   }
@@ -805,32 +891,30 @@ public class TestValueVector {
 
     // Create a new value vector for 1024 integers.
     try (final NullableVarCharVector vector = newNullableVarCharVector(EMPTY_SCHEMA_PATH, allocator)) {
-      final NullableVarCharVector.Mutator m = vector.getMutator();
       vector.allocateNew(1024 * 10, 1024);
 
-      m.set(0, STR1);
-      m.set(1, STR2);
-      m.set(2, STR3);
-      m.setSafe(3, STR3, 1, STR3.length - 1);
-      m.setSafe(4, STR3, 2, STR3.length - 2);
+      vector.set(0, STR1);
+      vector.set(1, STR2);
+      vector.set(2, STR3);
+      vector.setSafe(3, STR3, 1, STR3.length - 1);
+      vector.setSafe(4, STR3, 2, STR3.length - 2);
       ByteBuffer STR3ByteBuffer = ByteBuffer.wrap(STR3);
-      m.setSafe(5, STR3ByteBuffer, 1, STR3.length - 1);
-      m.setSafe(6, STR3ByteBuffer, 2, STR3.length - 2);
+      vector.setSafe(5, STR3ByteBuffer, 1, STR3.length - 1);
+      vector.setSafe(6, STR3ByteBuffer, 2, STR3.length - 2);
 
       // Check the sample strings.
-      final NullableVarCharVector.Accessor accessor = vector.getAccessor();
-      assertArrayEquals(STR1, accessor.get(0));
-      assertArrayEquals(STR2, accessor.get(1));
-      assertArrayEquals(STR3, accessor.get(2));
-      assertArrayEquals(Arrays.copyOfRange(STR3, 1, STR3.length), accessor.get(3));
-      assertArrayEquals(Arrays.copyOfRange(STR3, 2, STR3.length), accessor.get(4));
-      assertArrayEquals(Arrays.copyOfRange(STR3, 1, STR3.length), accessor.get(5));
-      assertArrayEquals(Arrays.copyOfRange(STR3, 2, STR3.length), accessor.get(6));
+      assertArrayEquals(STR1, vector.get(0));
+      assertArrayEquals(STR2, vector.get(1));
+      assertArrayEquals(STR3, vector.get(2));
+      assertArrayEquals(Arrays.copyOfRange(STR3, 1, STR3.length), vector.get(3));
+      assertArrayEquals(Arrays.copyOfRange(STR3, 2, STR3.length), vector.get(4));
+      assertArrayEquals(Arrays.copyOfRange(STR3, 1, STR3.length), vector.get(5));
+      assertArrayEquals(Arrays.copyOfRange(STR3, 2, STR3.length), vector.get(6));
 
       // Ensure null value throws.
       boolean b = false;
       try {
-        vector.getAccessor().get(7);
+        vector.get(7);
       } catch (IllegalStateException e) {
         b = true;
       } finally {
@@ -1070,43 +1154,42 @@ public class TestValueVector {
   @Test /* NullableVarCharVector */
   public void testReallocAfterVectorTransfer3() {
     try (final NullableVarCharVector vector = new NullableVarCharVector(EMPTY_SCHEMA_PATH, allocator)) {
-      final NullableVarCharVector.Mutator mutator = vector.getMutator();
-      final NullableVarCharVector.Accessor accessor = vector.getAccessor();
-
       /* 4096 values with 10 byte per record */
       vector.allocateNew(4096 * 10, 4096);
       int valueCapacity = vector.getValueCapacity();
+      assertEquals(4096, valueCapacity);
 
       /* populate the vector */
       for (int i = 0; i < valueCapacity; i++) {
         if ((i & 1) == 1) {
-          mutator.set(i, STR1);
+          vector.set(i, STR1);
         }
         else {
-          mutator.set(i, STR2);
+          vector.set(i, STR2);
         }
       }
 
       /* Check the vector output */
       for (int i = 0; i < valueCapacity; i++) {
         if ((i & 1) == 1) {
-          assertArrayEquals(STR1, accessor.get(i));
+          assertArrayEquals(STR1, vector.get(i));
         }
         else {
-          assertArrayEquals(STR2, accessor.get(i));
+          assertArrayEquals(STR2, vector.get(i));
         }
       }
 
       /* trigger first realloc */
-      mutator.setSafe(valueCapacity, STR2, 0, STR2.length);
+      vector.setSafe(valueCapacity, STR2, 0, STR2.length);
+      assertEquals(valueCapacity * 2, vector.getValueCapacity());
 
       /* populate the remaining vector */
       for (int i = valueCapacity; i < vector.getValueCapacity(); i++) {
         if ((i & 1) == 1) {
-          mutator.set(i, STR1);
+          vector.set(i, STR1);
         }
         else {
-          mutator.set(i, STR2);
+          vector.set(i, STR2);
         }
       }
 
@@ -1114,23 +1197,24 @@ public class TestValueVector {
       valueCapacity = vector.getValueCapacity();
       for (int i = 0; i < valueCapacity; i++) {
         if ((i & 1) == 1) {
-          assertArrayEquals(STR1, accessor.get(i));
+          assertArrayEquals(STR1, vector.get(i));
         }
         else {
-          assertArrayEquals(STR2, accessor.get(i));
+          assertArrayEquals(STR2, vector.get(i));
         }
       }
 
       /* trigger second realloc */
-      mutator.setSafe(valueCapacity + 10, STR2, 0, STR2.length);
+      vector.setSafe(valueCapacity + 10, STR2, 0, STR2.length);
+      assertEquals(valueCapacity * 2, vector.getValueCapacity());
 
       /* populate the remaining vector */
       for (int i = valueCapacity; i < vector.getValueCapacity(); i++) {
         if ((i & 1) == 1) {
-          mutator.set(i, STR1);
+          vector.set(i, STR1);
         }
         else {
-          mutator.set(i, STR2);
+          vector.set(i, STR2);
         }
       }
 
@@ -1138,10 +1222,10 @@ public class TestValueVector {
       valueCapacity = vector.getValueCapacity();
       for (int i = 0; i < valueCapacity; i++) {
         if ((i & 1) == 1) {
-          assertArrayEquals(STR1, accessor.get(i));
+          assertArrayEquals(STR1, vector.get(i));
         }
         else {
-          assertArrayEquals(STR2, accessor.get(i));
+          assertArrayEquals(STR2, vector.get(i));
         }
       }
 
@@ -1152,13 +1236,112 @@ public class TestValueVector {
       TransferPair transferPair = vector.getTransferPair(allocator);
       transferPair.transfer();
       NullableVarCharVector toVector = (NullableVarCharVector)transferPair.getTo();
-      NullableVarCharVector.Mutator toMutator = toVector.getMutator();
-      NullableVarCharVector.Accessor toAccessor = toVector.getAccessor();
-
       valueCapacity = toVector.getValueCapacity();
 
-      /* trigger a realloc of this toVector */
-      toMutator.setSafe(valueCapacity + 10, STR2, 0, STR2.length);
+      for (int i = 0; i < valueCapacity; i++) {
+        if ((i & 1) == 1) {
+          assertArrayEquals(STR1, toVector.get(i));
+        }
+        else {
+          assertArrayEquals(STR2, toVector.get(i));
+        }
+      }
+
+      toVector.close();
+    }
+  }
+
+  @Test /* NullableIntVector */
+  public void testReallocAfterVectorTransfer4() {
+    try (final NullableIntVector vector = new NullableIntVector(EMPTY_SCHEMA_PATH, allocator)) {
+
+      /* 4096 values  */
+      vector.allocateNew(4096);
+      int valueCapacity = vector.getValueCapacity();
+      assertEquals(4096, valueCapacity);
+
+      /* populate the vector */
+      int baseValue = 1000;
+      for (int i = 0; i < valueCapacity; i++) {
+        if ((i & 1) == 0) {
+          vector.set(i, 1000 + i);
+        }
+      }
+
+      /* Check the vector output */
+      for (int i = 0; i < valueCapacity; i++) {
+        if ((i & 1) == 0) {
+          assertEquals(1000 + i, vector.get(i));
+        }
+        else {
+          assertTrue(vector.isNull(i));
+        }
+      }
+
+      /* trigger first realloc */
+      vector.setSafe(valueCapacity, 10000000);
+      assertEquals(valueCapacity * 2, vector.getValueCapacity());
+
+      /* populate the remaining vector */
+      for (int i = valueCapacity; i < vector.getValueCapacity(); i++) {
+        if ((i & 1) == 0) {
+          vector.set(i, 1000 + i);
+        }
+      }
+
+      /* Check the vector output */
+      valueCapacity = vector.getValueCapacity();
+      for (int i = 0; i < valueCapacity; i++) {
+        if ((i & 1) == 0) {
+          assertEquals(1000 + i, vector.get(i));
+        }
+        else {
+          assertTrue(vector.isNull(i));
+        }
+      }
+
+      /* trigger second realloc */
+      vector.setSafe(valueCapacity, 10000000);
+      assertEquals(valueCapacity * 2, vector.getValueCapacity());
+
+      /* populate the remaining vector */
+      for (int i = valueCapacity; i < vector.getValueCapacity(); i++) {
+        if ((i & 1) == 0) {
+          vector.set(i, 1000 + i);
+        }
+      }
+
+      /* Check the vector output */
+      valueCapacity = vector.getValueCapacity();
+      for (int i = 0; i < valueCapacity; i++) {
+        if ((i & 1) == 0) {
+          assertEquals(1000 + i, vector.get(i));
+        }
+        else {
+          assertTrue(vector.isNull(i));
+        }
+      }
+
+      /* we are potentially working with 4x the size of vector buffer
+       * that we initially started with. Now let's transfer the vector.
+       */
+
+      TransferPair transferPair = vector.getTransferPair(allocator);
+      transferPair.transfer();
+      NullableIntVector toVector = (NullableIntVector)transferPair.getTo();
+      /* value capacity of source and target vectors should be same after
+       * the transfer.
+       */
+      assertEquals(valueCapacity, toVector.getValueCapacity());
+
+      for (int i = 0; i < valueCapacity; i++) {
+        if ((i & 1) == 0) {
+          assertEquals(1000 + i, toVector.get(i));
+        }
+        else {
+          assertTrue(toVector.isNull(i));
+        }
+      }
 
       toVector.close();
     }
@@ -1199,31 +1382,33 @@ public class TestValueVector {
 
   @Test
   public void testReAllocNullableVariableWidthVector() {
-    // Create a new value vector for 1024 integers
     try (final NullableVarCharVector vector = newVector(NullableVarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator)) {
-      final NullableVarCharVector.Mutator m = vector.getMutator();
       vector.allocateNew();
 
       int initialCapacity = vector.getValueCapacity();
+      assertEquals(4095, initialCapacity);
 
-      // Put values in indexes that fall within the initial allocation
-      m.setSafe(0, STR1, 0, STR1.length);
-      m.setSafe(initialCapacity - 1, STR2, 0, STR2.length);
+      /* Put values in indexes that fall within the initial allocation */
+      vector.setSafe(0, STR1, 0, STR1.length);
+      vector.setSafe(initialCapacity - 1, STR2, 0, STR2.length);
 
-      // Now try to put values in space that falls beyond the initial allocation
-      m.setSafe(initialCapacity + 200, STR3, 0, STR3.length);
+      /* the above set calls should NOT have triggered a realloc */
+      initialCapacity = vector.getValueCapacity();
+      assertEquals(4095, initialCapacity);
 
-      // Check valueCapacity is more than initial allocation
-      assertEquals((initialCapacity + 1) * 2 - 1, vector.getValueCapacity());
+      /* Now try to put values in space that falls beyond the initial allocation */
+      vector.setSafe(initialCapacity + 200, STR3, 0, STR3.length);
 
-      final NullableVarCharVector.Accessor accessor = vector.getAccessor();
-      assertArrayEquals(STR1, accessor.get(0));
-      assertArrayEquals(STR2, accessor.get(initialCapacity - 1));
-      assertArrayEquals(STR3, accessor.get(initialCapacity + 200));
+      /* Check valueCapacity is more than initial allocation */
+      assertEquals(((initialCapacity + 1) * 2) - 1, vector.getValueCapacity());
+
+      assertArrayEquals(STR1, vector.get(0));
+      assertArrayEquals(STR2, vector.get(initialCapacity - 1));
+      assertArrayEquals(STR3, vector.get(initialCapacity + 200));
 
       // Set the valueCount to be more than valueCapacity of current allocation. This is possible for NullableValueVectors
       // as we don't call setSafe for null values, but we do call setValueCount when the current batch is processed.
-      m.setValueCount(vector.getValueCapacity() + 200);
+      vector.setValueCount(vector.getValueCapacity() + 200);
     }
   }
 
@@ -1232,10 +1417,18 @@ public class TestValueVector {
     try (final NullableVarCharVector vector = newVector(NullableVarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator)) {
       vector.allocateNew();
 
-      vector.getMutator().setSafe(4094, "hello".getBytes(), 0, 5);
-      vector.getMutator().setValueCount(4095);
+      int initialCapacity = vector.getValueCapacity();
+      assertEquals(4095, initialCapacity);
+
+      vector.setSafe(4094, "hello".getBytes(), 0, 5);
+      /* the above set method should NOT have trigerred a realloc */
+      initialCapacity = vector.getValueCapacity();
+      assertEquals(4095, initialCapacity);
 
-      assertEquals(4096 * 4, vector.getFieldBuffers().get(1).capacity());
+      vector.setValueCount(4095);
+      assertEquals(4096 * vector.OFFSET_WIDTH, vector.getFieldBuffers().get(1).capacity());
+      initialCapacity = vector.getValueCapacity();
+      assertEquals(4095, initialCapacity);
     }
   }
 
@@ -1243,42 +1436,129 @@ public class TestValueVector {
   public void testCopyFromWithNulls() {
     try (final NullableVarCharVector vector = newVector(NullableVarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator);
          final NullableVarCharVector vector2 = newVector(NullableVarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator)) {
+
       vector.allocateNew();
+      int capacity = vector.getValueCapacity();
+      assertEquals(4095, capacity);
 
       for (int i = 0; i < 4095; i++) {
         if (i % 3 == 0) {
           continue;
         }
         byte[] b = Integer.toString(i).getBytes();
-        vector.getMutator().setSafe(i, b, 0, b.length);
+        vector.setSafe(i, b, 0, b.length);
       }
 
-      vector.getMutator().setValueCount(4095);
+      /* NO reAlloc() should have happened in setSafe() */
+      capacity = vector.getValueCapacity();
+      assertEquals(4095, capacity);
+
+      vector.setValueCount(4095);
+
+      for (int i = 0; i < 4095; i++) {
+        if (i % 3 == 0) {
+          assertNull(vector.getObject(i));
+        } else {
+          assertEquals("unexpected value at index: " + i, Integer.toString(i), vector.getObject(i).toString());
+        }
+      }
 
       vector2.allocateNew();
+      capacity = vector2.getValueCapacity();
+      assertEquals(4095, capacity);
 
       for (int i = 0; i < 4095; i++) {
         vector2.copyFromSafe(i, i, vector);
+        if (i % 3 == 0) {
+          assertNull(vector2.getObject(i));
+        } else {
+          assertEquals("unexpected value at index: " + i, Integer.toString(i), vector2.getObject(i).toString());
+        }
       }
 
-      vector2.getMutator().setValueCount(4095);
+      /* NO reAlloc() should have happened in copyFrom */
+      capacity = vector2.getValueCapacity();
+      assertEquals(4095, capacity);
+
+      vector2.setValueCount(4095);
 
       for (int i = 0; i < 4095; i++) {
         if (i % 3 == 0) {
-          assertNull(vector2.getAccessor().getObject(i));
+          assertNull(vector2.getObject(i));
         } else {
-          assertEquals(Integer.toString(i), vector2.getAccessor().getObject(i).toString());
+          assertEquals("unexpected value at index: " + i, Integer.toString(i), vector2.getObject(i).toString());
         }
       }
     }
   }
 
   @Test
-  public void testSetLastSetUsage() {
-    try (final NullableVarCharVector vector = new NullableVarCharVector("myvector", allocator)) {
+  public void testCopyFromWithNulls1() {
+    try (final NullableVarCharVector vector = newVector(NullableVarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator);
+         final NullableVarCharVector vector2 = newVector(NullableVarCharVector.class, EMPTY_SCHEMA_PATH, MinorType.VARCHAR, allocator)) {
 
-      final NullableVarCharVector.Mutator mutator = vector.getMutator();
+      vector.allocateNew();
+      int capacity = vector.getValueCapacity();
+      assertEquals(4095, capacity);
 
+      for (int i = 0; i < 4095; i++) {
+        if (i % 3 == 0) {
+          continue;
+        }
+        byte[] b = Integer.toString(i).getBytes();
+        vector.setSafe(i, b, 0, b.length);
+      }
+
+      /* NO reAlloc() should have happened in setSafe() */
+      capacity = vector.getValueCapacity();
+      assertEquals(4095, capacity);
+
+      vector.setValueCount(4095);
+
+      for (int i = 0; i < 4095; i++) {
+        if (i % 3 == 0) {
+          assertNull(vector.getObject(i));
+        } else {
+          assertEquals("unexpected value at index: " + i, Integer.toString(i), vector.getObject(i).toString());
+        }
+      }
+
+      /* set lesser initial capacity than actually needed
+       * to trigger reallocs in copyFromSafe()
+       */
+      vector2.allocateNew(1024 * 10, 1024);
+
+      capacity = vector2.getValueCapacity();
+      assertEquals(1024, capacity);
+
+      for (int i = 0; i < 4095; i++) {
+        vector2.copyFromSafe(i, i, vector);
+        if (i % 3 == 0) {
+          assertNull(vector2.getObject(i));
+        } else {
+          assertEquals("unexpected value at index: " + i, Integer.toString(i), vector2.getObject(i).toString());
+        }
+      }
+
+      /* 2 reAllocs should have happened in copyFromSafe() */
+      capacity = vector2.getValueCapacity();
+      assertEquals(4096, capacity);
+
+      vector2.setValueCount(4095);
+
+      for (int i = 0; i < 4095; i++) {
+        if (i % 3 == 0) {
+          assertNull(vector2.getObject(i));
+        } else {
+          assertEquals("unexpected value at index: " + i, Integer.toString(i), vector2.getObject(i).toString());
+        }
+      }
+    }
+  }
+
+  @Test
+  public void testSetLastSetUsage() {
+    try (final NullableVarCharVector vector = new NullableVarCharVector("myvector", allocator)) {
       vector.allocateNew(1024 * 10, 1024);
 
       setBytes(0, STR1, vector);
@@ -1289,32 +1569,102 @@ public class TestValueVector {
       setBytes(5, STR6, vector);
 
       /* Check current lastSet */
-      assertEquals(Integer.toString(-1), Integer.toString(mutator.getLastSet()));
+      assertEquals(Integer.toString(-1), Integer.toString(vector.getLastSet()));
 
       /* Check the vector output */
-      final NullableVarCharVector.Accessor accessor = vector.getAccessor();
-      assertArrayEquals(STR1, accessor.get(0));
-      assertArrayEquals(STR2, accessor.get(1));
-      assertArrayEquals(STR3, accessor.get(2));
-      assertArrayEquals(STR4, accessor.get(3));
-      assertArrayEquals(STR5, accessor.get(4));
-      assertArrayEquals(STR6, accessor.get(5));
+      assertArrayEquals(STR1, vector.get(0));
+      assertArrayEquals(STR2, vector.get(1));
+      assertArrayEquals(STR3, vector.get(2));
+      assertArrayEquals(STR4, vector.get(3));
+      assertArrayEquals(STR5, vector.get(4));
+      assertArrayEquals(STR6, vector.get(5));
 
       /*
        * If we don't do setLastSe(5) before setValueCount(), then the latter will corrupt
        * the value vector by filling in all positions [0,valuecount-1] will empty byte arrays.
        * Run the test by commenting out next line and we should see incorrect vector output.
        */
-      mutator.setLastSet(5);
-      mutator.setValueCount(20);
+      vector.setLastSet(5);
+      vector.setValueCount(20);
+
+      /* Check current lastSet */
+      assertEquals(Integer.toString(19), Integer.toString(vector.getLastSet()));
 
       /* Check the vector output again */
-      assertArrayEquals(STR1, accessor.get(0));
-      assertArrayEquals(STR2, accessor.get(1));
-      assertArrayEquals(STR3, accessor.get(2));
-      assertArrayEquals(STR4, accessor.get(3));
-      assertArrayEquals(STR5, accessor.get(4));
-      assertArrayEquals(STR6, accessor.get(5));
+      assertArrayEquals(STR1, vector.get(0));
+      assertArrayEquals(STR2, vector.get(1));
+      assertArrayEquals(STR3, vector.get(2));
+      assertArrayEquals(STR4, vector.get(3));
+      assertArrayEquals(STR5, vector.get(4));
+      assertArrayEquals(STR6, vector.get(5));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(6)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(7)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(8)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(9)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(10)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(11)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(12)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(13)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(14)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(15)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(16)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(17)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(18)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(19)));
+
+      /* Check offsets */
+      assertEquals(Integer.toString(0),
+              Integer.toString(vector.offsetBuffer.getInt(0 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(6),
+              Integer.toString(vector.offsetBuffer.getInt(1 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(16),
+              Integer.toString(vector.offsetBuffer.getInt(2 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(21),
+              Integer.toString(vector.offsetBuffer.getInt(3 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(30),
+              Integer.toString(vector.offsetBuffer.getInt(4 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(34),
+              Integer.toString(vector.offsetBuffer.getInt(5 * vector.OFFSET_WIDTH)));
+
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(6 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(7 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(8 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(9 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(10 * vector.OFFSET_WIDTH)));
+
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(11 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(12 * vector.OFFSET_WIDTH)));
+
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(13 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(14 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(15 * vector.OFFSET_WIDTH)));
+
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(16 * vector.OFFSET_WIDTH)));
+
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(17 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(18 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(19 * vector.OFFSET_WIDTH)));
+
+      vector.set(19, STR6);
+      assertArrayEquals(STR6, vector.get(19));
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(19 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(46),
+              Integer.toString(vector.offsetBuffer.getInt(20 * vector.OFFSET_WIDTH)));
     }
   }
 
@@ -1322,29 +1672,25 @@ public class TestValueVector {
   public void testVectorLoadUnload() {
 
     try (final NullableVarCharVector vector1 = new NullableVarCharVector("myvector", allocator)) {
-
-      final NullableVarCharVector.Mutator mutator1 = vector1.getMutator();
-
       vector1.allocateNew(1024 * 10, 1024);
 
-      mutator1.set(0, STR1);
-      mutator1.set(1, STR2);
-      mutator1.set(2, STR3);
-      mutator1.set(3, STR4);
-      mutator1.set(4, STR5);
-      mutator1.set(5, STR6);
-      assertEquals(Integer.toString(5), Integer.toString(mutator1.getLastSet()));
-      mutator1.setValueCount(15);
-      assertEquals(Integer.toString(14), Integer.toString(mutator1.getLastSet()));
+      vector1.set(0, STR1);
+      vector1.set(1, STR2);
+      vector1.set(2, STR3);
+      vector1.set(3, STR4);
+      vector1.set(4, STR5);
+      vector1.set(5, STR6);
+      assertEquals(Integer.toString(5), Integer.toString(vector1.getLastSet()));
+      vector1.setValueCount(15);
+      assertEquals(Integer.toString(14), Integer.toString(vector1.getLastSet()));
 
       /* Check the vector output */
-      final NullableVarCharVector.Accessor accessor1 = vector1.getAccessor();
-      assertArrayEquals(STR1, accessor1.get(0));
-      assertArrayEquals(STR2, accessor1.get(1));
-      assertArrayEquals(STR3, accessor1.get(2));
-      assertArrayEquals(STR4, accessor1.get(3));
-      assertArrayEquals(STR5, accessor1.get(4));
-      assertArrayEquals(STR6, accessor1.get(5));
+      assertArrayEquals(STR1, vector1.get(0));
+      assertArrayEquals(STR2, vector1.get(1));
+      assertArrayEquals(STR3, vector1.get(2));
+      assertArrayEquals(STR4, vector1.get(3));
+      assertArrayEquals(STR5, vector1.get(4));
+      assertArrayEquals(STR6, vector1.get(5));
 
       Field field = vector1.getField();
       String fieldName = field.getName();
@@ -1357,7 +1703,7 @@ public class TestValueVector {
 
       Schema schema = new Schema(fields);
 
-      VectorSchemaRoot schemaRoot1 = new VectorSchemaRoot(schema, fieldVectors, accessor1.getValueCount());
+      VectorSchemaRoot schemaRoot1 = new VectorSchemaRoot(schema, fieldVectors, vector1.getValueCount());
       VectorUnloader vectorUnloader = new VectorUnloader(schemaRoot1);
 
       try (
@@ -1370,24 +1716,21 @@ public class TestValueVector {
         vectorLoader.load(recordBatch);
 
         NullableVarCharVector vector2 = (NullableVarCharVector) schemaRoot2.getVector(fieldName);
-        NullableVarCharVector.Mutator mutator2 = vector2.getMutator();
-
         /*
          * lastSet would have internally been set by VectorLoader.load() when it invokes
          * loadFieldBuffers.
          */
-        assertEquals(Integer.toString(14), Integer.toString(mutator2.getLastSet()));
-        mutator2.setValueCount(25);
-        assertEquals(Integer.toString(24), Integer.toString(mutator2.getLastSet()));
+        assertEquals(Integer.toString(14), Integer.toString(vector2.getLastSet()));
+        vector2.setValueCount(25);
+        assertEquals(Integer.toString(24), Integer.toString(vector2.getLastSet()));
 
         /* Check the vector output */
-        final NullableVarCharVector.Accessor accessor2 = vector2.getAccessor();
-        assertArrayEquals(STR1, accessor2.get(0));
-        assertArrayEquals(STR2, accessor2.get(1));
-        assertArrayEquals(STR3, accessor2.get(2));
-        assertArrayEquals(STR4, accessor2.get(3));
-        assertArrayEquals(STR5, accessor2.get(4));
-        assertArrayEquals(STR6, accessor2.get(5));
+        assertArrayEquals(STR1, vector2.get(0));
+        assertArrayEquals(STR2, vector2.get(1));
+        assertArrayEquals(STR3, vector2.get(2));
+        assertArrayEquals(STR4, vector2.get(3));
+        assertArrayEquals(STR5, vector2.get(4));
+        assertArrayEquals(STR6, vector2.get(5));
       }
     }
   }
@@ -1396,8 +1739,6 @@ public class TestValueVector {
   public void testFillEmptiesUsage() {
     try (final NullableVarCharVector vector = new NullableVarCharVector("myvector", allocator)) {
 
-      final NullableVarCharVector.Mutator mutator = vector.getMutator();
-
       vector.allocateNew(1024 * 10, 1024);
 
       setBytes(0, STR1, vector);
@@ -1408,84 +1749,98 @@ public class TestValueVector {
       setBytes(5, STR6, vector);
 
       /* Check current lastSet */
-      assertEquals(Integer.toString(-1), Integer.toString(mutator.getLastSet()));
+      assertEquals(Integer.toString(-1), Integer.toString(vector.getLastSet()));
 
       /* Check the vector output */
-      final NullableVarCharVector.Accessor accessor = vector.getAccessor();
-      assertArrayEquals(STR1, accessor.get(0));
-      assertArrayEquals(STR2, accessor.get(1));
-      assertArrayEquals(STR3, accessor.get(2));
-      assertArrayEquals(STR4, accessor.get(3));
-      assertArrayEquals(STR5, accessor.get(4));
-      assertArrayEquals(STR6, accessor.get(5));
-
-      mutator.setLastSet(5);
+      assertArrayEquals(STR1, vector.get(0));
+      assertArrayEquals(STR2, vector.get(1));
+      assertArrayEquals(STR3, vector.get(2));
+      assertArrayEquals(STR4, vector.get(3));
+      assertArrayEquals(STR5, vector.get(4));
+      assertArrayEquals(STR6, vector.get(5));
+
+      vector.setLastSet(5);
       /* fill empty byte arrays from index [6, 9] */
-      mutator.fillEmpties(10);
+      vector.fillEmpties(10);
 
       /* Check current lastSet */
-      assertEquals(Integer.toString(9), Integer.toString(mutator.getLastSet()));
+      assertEquals(Integer.toString(9), Integer.toString(vector.getLastSet()));
 
       /* Check the vector output */
-      assertArrayEquals(STR1, accessor.get(0));
-      assertArrayEquals(STR2, accessor.get(1));
-      assertArrayEquals(STR3, accessor.get(2));
-      assertArrayEquals(STR4, accessor.get(3));
-      assertArrayEquals(STR5, accessor.get(4));
-      assertArrayEquals(STR6, accessor.get(5));
-      assertEquals(Integer.toString(0), Integer.toString(accessor.getValueLength(6)));
-      assertEquals(Integer.toString(0), Integer.toString(accessor.getValueLength(7)));
-      assertEquals(Integer.toString(0), Integer.toString(accessor.getValueLength(8)));
-      assertEquals(Integer.toString(0), Integer.toString(accessor.getValueLength(9)));
+      assertArrayEquals(STR1, vector.get(0));
+      assertArrayEquals(STR2, vector.get(1));
+      assertArrayEquals(STR3, vector.get(2));
+      assertArrayEquals(STR4, vector.get(3));
+      assertArrayEquals(STR5, vector.get(4));
+      assertArrayEquals(STR6, vector.get(5));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(6)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(7)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(8)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(9)));
 
       setBytes(10, STR1, vector);
       setBytes(11, STR2, vector);
 
-      mutator.setLastSet(11);
+      vector.setLastSet(11);
       /* fill empty byte arrays from index [12, 14] */
-      mutator.setValueCount(15);
+      vector.setValueCount(15);
 
       /* Check current lastSet */
-      assertEquals(Integer.toString(14), Integer.toString(mutator.getLastSet()));
+      assertEquals(Integer.toString(14), Integer.toString(vector.getLastSet()));
 
       /* Check the vector output */
-      assertArrayEquals(STR1, accessor.get(0));
-      assertArrayEquals(STR2, accessor.get(1));
-      assertArrayEquals(STR3, accessor.get(2));
-      assertArrayEquals(STR4, accessor.get(3));
-      assertArrayEquals(STR5, accessor.get(4));
-      assertArrayEquals(STR6, accessor.get(5));
-      assertEquals(Integer.toString(0), Integer.toString(accessor.getValueLength(6)));
-      assertEquals(Integer.toString(0), Integer.toString(accessor.getValueLength(7)));
-      assertEquals(Integer.toString(0), Integer.toString(accessor.getValueLength(8)));
-      assertEquals(Integer.toString(0), Integer.toString(accessor.getValueLength(9)));
-      assertArrayEquals(STR1, accessor.get(10));
-      assertArrayEquals(STR2, accessor.get(11));
-      assertEquals(Integer.toString(0), Integer.toString(accessor.getValueLength(12)));
-      assertEquals(Integer.toString(0), Integer.toString(accessor.getValueLength(13)));
-      assertEquals(Integer.toString(0), Integer.toString(accessor.getValueLength(14)));
+      assertArrayEquals(STR1, vector.get(0));
+      assertArrayEquals(STR2, vector.get(1));
+      assertArrayEquals(STR3, vector.get(2));
+      assertArrayEquals(STR4, vector.get(3));
+      assertArrayEquals(STR5, vector.get(4));
+      assertArrayEquals(STR6, vector.get(5));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(6)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(7)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(8)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(9)));
+      assertArrayEquals(STR1, vector.get(10));
+      assertArrayEquals(STR2, vector.get(11));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(12)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(13)));
+      assertEquals(Integer.toString(0), Integer.toString(vector.getValueLength(14)));
 
       /* Check offsets */
-      final UInt4Vector.Accessor offsetAccessor = vector.values.offsetVector.getAccessor();
-      assertEquals(Integer.toString(0), Integer.toString(offsetAccessor.get(0)));
-      assertEquals(Integer.toString(6), Integer.toString(offsetAccessor.get(1)));
-      assertEquals(Integer.toString(16), Integer.toString(offsetAccessor.get(2)));
-      assertEquals(Integer.toString(21), Integer.toString(offsetAccessor.get(3)));
-      assertEquals(Integer.toString(30), Integer.toString(offsetAccessor.get(4)));
-      assertEquals(Integer.toString(34), Integer.toString(offsetAccessor.get(5)));
-
-      assertEquals(Integer.toString(40), Integer.toString(offsetAccessor.get(6)));
-      assertEquals(Integer.toString(40), Integer.toString(offsetAccessor.get(7)));
-      assertEquals(Integer.toString(40), Integer.toString(offsetAccessor.get(8)));
-      assertEquals(Integer.toString(40), Integer.toString(offsetAccessor.get(9)));
-      assertEquals(Integer.toString(40), Integer.toString(offsetAccessor.get(10)));
-
-      assertEquals(Integer.toString(46), Integer.toString(offsetAccessor.get(11)));
-      assertEquals(Integer.toString(56), Integer.toString(offsetAccessor.get(12)));
-
-      assertEquals(Integer.toString(56), Integer.toString(offsetAccessor.get(13)));
-      assertEquals(Integer.toString(56), Integer.toString(offsetAccessor.get(14)));
-      assertEquals(Integer.toString(56), Integer.toString(offsetAccessor.get(15)));
+      assertEquals(Integer.toString(0),
+              Integer.toString(vector.offsetBuffer.getInt(0 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(6),
+              Integer.toString(vector.offsetBuffer.getInt(1 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(16),
+              Integer.toString(vector.offsetBuffer.getInt(2 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(21),
+              Integer.toString(vector.offsetBuffer.getInt(3 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(30),
+              Integer.toString(vector.offsetBuffer.getInt(4 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(34),
+              Integer.toString(vector.offsetBuffer.getInt(5 * vector.OFFSET_WIDTH)));
+
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(6 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(7 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(8 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(9 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(40),
+              Integer.toString(vector.offsetBuffer.getInt(10 * vector.OFFSET_WIDTH)));
+
+      assertEquals(Integer.toString(46),
+              Integer.toString(vector.offsetBuffer.getInt(11 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(56),
+              Integer.toString(vector.offsetBuffer.getInt(12 * vector.OFFSET_WIDTH)));
+
+      assertEquals(Integer.toString(56),
+              Integer.toString(vector.offsetBuffer.getInt(13 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(56),
+              Integer.toString(vector.offsetBuffer.getInt(14 * vector.OFFSET_WIDTH)));
+      assertEquals(Integer.toString(56),
+              Integer.toString(vector.offsetBuffer.getInt(15 * vector.OFFSET_WIDTH)));
     }
   }
 
@@ -1493,29 +1848,25 @@ public class TestValueVector {
   public void testGetBufferAddress1() {
 
     try (final NullableVarCharVector vector = new NullableVarCharVector("myvector", allocator)) {
-
-      final NullableVarCharVector.Mutator mutator = vector.getMutator();
-      final NullableVarCharVector.Accessor accessor = vector.getAccessor();
-
       vector.allocateNew(1024 * 10, 1024);
 
       /* populate the vector */
-      mutator.set(0, STR1);
-      mutator.set(1, STR2);
-      mutator.set(2, STR3);
-      mutator.set(3, STR4);
-      mutator.set(4, STR5);
-      mutator.set(5, STR6);
+      vector.set(0, STR1);
+      vector.set(1, STR2);
+      vector.set(2, STR3);
+      vector.set(3, STR4);
+      vector.set(4, STR5);
+      vector.set(5, STR6);
 
-      mutator.setValueCount(15);
+      vector.setValueCount(15);
 
       /* check the vector output */
-      assertArrayEquals(STR1, accessor.get(0));
-      assertArrayEquals(STR2, accessor.get(1));
-      assertArrayEquals(STR3, accessor.get(2));
-      assertArrayEquals(STR4, accessor.get(3));
-      assertArrayEquals(STR5, accessor.get(4));
-      assertArrayEquals(STR6, accessor.get(5));
+      assertArrayEquals(STR1, vector.get(0));
+      assertArrayEquals(STR2, vector.get(1));
+      assertArrayEquals(STR3, vector.get(2));
+      assertArrayEquals(STR4, vector.get(3));
+      assertArrayEquals(STR5, vector.get(4));
+      assertArrayEquals(STR6, vector.get(5));
 
       List<ArrowBuf> buffers = vector.getFieldBuffers();
       long bitAddress = vector.getValidityBufferAddress();
@@ -1531,23 +1882,18 @@ public class TestValueVector {
 
   @Test /* NullableIntVector */
   public void testGetBufferAddress2() {
-
     try (final NullableIntVector vector = new NullableIntVector("myvector", allocator)) {
-
-      final NullableIntVector.Mutator mutator = vector.getMutator();
-      final NullableIntVector.Accessor accessor = vector.getAccessor();
       boolean error = false;
-
       vector.allocateNew(16);
 
       /* populate the vector */
       for(int i = 0; i < 16; i += 2) {
-        mutator.set(i, i+10);
+        vector.set(i, i+10);
       }
 
       /* check the vector output */
       for(int i = 0; i < 16; i += 2) {
-        assertEquals(i+10, accessor.get(i));
+        assertEquals(i+10, vector.get(i));
       }
 
       List<ArrowBuf> buffers = vector.getFieldBuffers();
@@ -1580,11 +1926,15 @@ public class TestValueVector {
     vectorAllocator.close();
   }
 
+  /* this method is used by the tests to bypass the vector set methods that manipulate
+   * lastSet. The method is to test the lastSet property and that's why we load the vector
+   * in a way that lastSet is not set automatically.
+   */
   public static void setBytes(int index, byte[] bytes, NullableVarCharVector vector) {
-    final int currentOffset = vector.values.offsetVector.getAccessor().get(index);
+    final int currentOffset = vector.offsetBuffer.getInt(index * vector.OFFSET_WIDTH);
 
-    vector.bits.getMutator().setToOne(index);
-    vector.values.offsetVector.getMutator().set(index + 1, currentOffset + bytes.length);
-    vector.values.data.setBytes(currentOffset, bytes, 0, bytes.length);
+    BitVectorHelper.setValidityBitToOne(vector.validityBuffer, index);
+    vector.offsetBuffer.setInt((index + 1) * vector.OFFSET_WIDTH, currentOffset + bytes.length);
+    vector.valueBuffer.setBytes(currentOffset, bytes, 0, bytes.length);
   }
 }

http://git-wip-us.apache.org/repos/asf/arrow/blob/60a2ebdf/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 4ac7536..531a46c 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
@@ -76,24 +76,23 @@ public class TestVectorReAlloc {
   @Test
   public void testNullableType() {
     try (final NullableVarCharVector vector = new NullableVarCharVector("", allocator)) {
-      final NullableVarCharVector.Mutator m = vector.getMutator();
       vector.setInitialCapacity(512);
       vector.allocateNew();
 
       assertEquals(512, vector.getValueCapacity());
 
       try {
-        m.set(512, "foo".getBytes(StandardCharsets.UTF_8));
+        vector.set(512, "foo".getBytes(StandardCharsets.UTF_8));
         Assert.fail("Expected out of bounds exception");
       } catch (Exception e) {
         // ok
       }
 
       vector.reAlloc();
-      assertEquals(1023, vector.getValueCapacity());
+      assertEquals(1024, vector.getValueCapacity());
 
-      m.set(512, "foo".getBytes(StandardCharsets.UTF_8));
-      assertEquals("foo", new String(vector.getAccessor().get(512), StandardCharsets.UTF_8));
+      vector.set(512, "foo".getBytes(StandardCharsets.UTF_8));
+      assertEquals("foo", new String(vector.get(512), StandardCharsets.UTF_8));
     }
   }
 
@@ -105,7 +104,7 @@ public class TestVectorReAlloc {
       vector.setInitialCapacity(512);
       vector.allocateNew();
 
-      assertEquals(1023, vector.getValueCapacity()); // TODO this doubles for some reason...
+      assertEquals(1023, vector.getValueCapacity());
 
       try {
         vector.getOffsetVector().getAccessor().get(2014);

http://git-wip-us.apache.org/repos/asf/arrow/blob/60a2ebdf/java/vector/src/test/java/org/apache/arrow/vector/TestVectorUnloadLoad.java
----------------------------------------------------------------------
diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorUnloadLoad.java b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorUnloadLoad.java
index 7facf73..0b7928d 100644
--- a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorUnloadLoad.java
+++ b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorUnloadLoad.java
@@ -45,13 +45,21 @@ import org.apache.arrow.vector.types.pojo.ArrowType;
 import org.apache.arrow.vector.types.pojo.Field;
 import org.apache.arrow.vector.types.pojo.FieldType;
 import org.apache.arrow.vector.types.pojo.Schema;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.*;
 
 public class TestVectorUnloadLoad {
 
-  static final BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE);
+  private BufferAllocator allocator;
+
+  @Before
+  public void init() {
+    allocator = new RootAllocator(Long.MAX_VALUE);
+  }
+
+  @After
+  public void terminate() throws Exception {
+    allocator.close();
+  }
 
   @Test
   public void testUnloadLoad() throws IOException {
@@ -183,24 +191,40 @@ public class TestVectorUnloadLoad {
    * @throws IOException
    */
   @Test
-  public void testLoadEmptyValidityBuffer() throws IOException {
+  public void testLoadValidityBuffer() throws IOException {
     Schema schema = new Schema(asList(
         new Field("intDefined", FieldType.nullable(new ArrowType.Int(32, true)), Collections.<Field>emptyList()),
         new Field("intNull", FieldType.nullable(new ArrowType.Int(32, true)), Collections.<Field>emptyList())
     ));
     int count = 10;
-    ArrowBuf validity = allocator.buffer(10).slice(0, 0);
-    ArrowBuf[] values = new ArrowBuf[2];
-    for (int i = 0; i < values.length; i++) {
-      ArrowBuf arrowBuf = allocator.buffer(count * 4); // integers
-      values[i] = arrowBuf;
+    ArrowBuf[] values = new ArrowBuf[4];
+    for (int i = 0; i < 4; i+=2) {
+      ArrowBuf buf1 = allocator.buffer((int)Math.ceil(count / 8.0));
+      ArrowBuf buf2 = allocator.buffer(count * 4); // integers
+      values[i] = buf1;
+      values[i+1] = buf2;
       for (int j = 0; j < count; j++) {
-        arrowBuf.setInt(j * 4, j);
+        if (i == 2) {
+          BitVectorHelper.setValidityBit(buf1, j, 0);
+        } else {
+          BitVectorHelper.setValidityBitToOne(buf1, j);
+        }
+
+        buf2.setInt(j * 4, j);
       }
-      arrowBuf.writerIndex(count * 4);
+      buf1.writerIndex((int)Math.ceil(count / 8));
+      buf2.writerIndex(count * 4);
     }
+
+    /*
+     * values[0] - validity buffer for first vector
+     * values[1] - data buffer for first vector
+     * values[2] - validity buffer for second vector
+     * values[3] - data buffer for second vector
+     */
+
     try (
-        ArrowRecordBatch recordBatch = new ArrowRecordBatch(count, asList(new ArrowFieldNode(count, 0), new ArrowFieldNode(count, count)), asList(validity, values[0], validity, values[1]));
+        ArrowRecordBatch recordBatch = new ArrowRecordBatch(count, asList(new ArrowFieldNode(count, 0), new ArrowFieldNode(count, count)), asList(values[0], values[1], values[2], values[3]));
         BufferAllocator finalVectorsAllocator = allocator.newChildAllocator("final vectors", 0, Integer.MAX_VALUE);
         VectorSchemaRoot newRoot = VectorSchemaRoot.create(schema, finalVectorsAllocator);
     ) {
@@ -213,32 +237,31 @@ public class TestVectorUnloadLoad {
       NullableIntVector intDefinedVector = (NullableIntVector) newRoot.getVector("intDefined");
       NullableIntVector intNullVector = (NullableIntVector) newRoot.getVector("intNull");
       for (int i = 0; i < count; i++) {
-        assertFalse("#" + i, intDefinedVector.getAccessor().isNull(i));
-        assertEquals("#" + i, i, intDefinedVector.getAccessor().get(i));
-        assertTrue("#" + i, intNullVector.getAccessor().isNull(i));
+        assertFalse("#" + i, intDefinedVector.isNull(i));
+        assertEquals("#" + i, i, intDefinedVector.get(i));
+        assertTrue("#" + i, intNullVector.isNull(i));
       }
-      intDefinedVector.getMutator().setSafe(count + 10, 1234);
-      assertTrue(intDefinedVector.getAccessor().isNull(count + 1));
+      intDefinedVector.setSafe(count + 10, 1234);
+      assertTrue(intDefinedVector.isNull(count + 1));
       // empty slots should still default to unset
-      intDefinedVector.getMutator().setSafe(count + 1, 789);
-      assertFalse(intDefinedVector.getAccessor().isNull(count + 1));
-      assertEquals(789, intDefinedVector.getAccessor().get(count + 1));
-      assertTrue(intDefinedVector.getAccessor().isNull(count));
-      assertTrue(intDefinedVector.getAccessor().isNull(count + 2));
-      assertTrue(intDefinedVector.getAccessor().isNull(count + 3));
-      assertTrue(intDefinedVector.getAccessor().isNull(count + 4));
-      assertTrue(intDefinedVector.getAccessor().isNull(count + 5));
-      assertTrue(intDefinedVector.getAccessor().isNull(count + 6));
-      assertTrue(intDefinedVector.getAccessor().isNull(count + 7));
-      assertTrue(intDefinedVector.getAccessor().isNull(count + 8));
-      assertTrue(intDefinedVector.getAccessor().isNull(count + 9));
-      assertFalse(intDefinedVector.getAccessor().isNull(count + 10));
-      assertEquals(1234, intDefinedVector.getAccessor().get(count + 10));
+      intDefinedVector.setSafe(count + 1, 789);
+      assertFalse(intDefinedVector.isNull(count + 1));
+      assertEquals(789, intDefinedVector.get(count + 1));
+      assertTrue(intDefinedVector.isNull(count));
+      assertTrue(intDefinedVector.isNull(count + 2));
+      assertTrue(intDefinedVector.isNull(count + 3));
+      assertTrue(intDefinedVector.isNull(count + 4));
+      assertTrue(intDefinedVector.isNull(count + 5));
+      assertTrue(intDefinedVector.isNull(count + 6));
+      assertTrue(intDefinedVector.isNull(count + 7));
+      assertTrue(intDefinedVector.isNull(count + 8));
+      assertTrue(intDefinedVector.isNull(count + 9));
+      assertFalse(intDefinedVector.isNull(count + 10));
+      assertEquals(1234, intDefinedVector.get(count + 10));
     } finally {
       for (ArrowBuf arrowBuf : values) {
         arrowBuf.release();
       }
-      validity.release();
     }
   }
 
@@ -258,11 +281,11 @@ public class TestVectorUnloadLoad {
         FieldVector vector = field.createVector(originalVectorsAllocator);
         vector.allocateNew();
         sources.add(vector);
-        NullableIntVector.Mutator mutator = (NullableIntVector.Mutator) vector.getMutator();
+        NullableIntVector intVector = (NullableIntVector)vector;
         for (int i = 0; i < count; i++) {
-          mutator.set(i, i);
+          intVector.set(i, i);
         }
-        mutator.setValueCount(count);
+        intVector.setValueCount(count);
       }
 
       try (VectorSchemaRoot root = new VectorSchemaRoot(schema.getFields(), sources, count)) {
@@ -277,8 +300,8 @@ public class TestVectorUnloadLoad {
           List<FieldVector> targets = newRoot.getFieldVectors();
           Assert.assertEquals(sources.size(), targets.size());
           for (int k = 0; k < sources.size(); k++) {
-            NullableIntVector.Accessor src = (NullableIntVector.Accessor) sources.get(k).getAccessor();
-            NullableIntVector.Accessor tgt = (NullableIntVector.Accessor) targets.get(k).getAccessor();
+            NullableIntVector src = (NullableIntVector) sources.get(k);
+            NullableIntVector tgt = (NullableIntVector) targets.get(k);
             Assert.assertEquals(src.getValueCount(), tgt.getValueCount());
             for (int i = 0; i < count; i++) {
               Assert.assertEquals(src.get(i), tgt.get(i));
@@ -296,9 +319,4 @@ public class TestVectorUnloadLoad {
     VectorSchemaRoot vsr = new VectorSchemaRoot(schema.getFields(), fields, valueCount);
     return new VectorUnloader(vsr);
   }
-
-  @AfterClass
-  public static void afterClass() {
-    allocator.close();
-  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/arrow/blob/60a2ebdf/java/vector/src/test/java/org/apache/arrow/vector/file/BaseFileTest.java
----------------------------------------------------------------------
diff --git a/java/vector/src/test/java/org/apache/arrow/vector/file/BaseFileTest.java b/java/vector/src/test/java/org/apache/arrow/vector/file/BaseFileTest.java
index ba62de0..60009b0 100644
--- a/java/vector/src/test/java/org/apache/arrow/vector/file/BaseFileTest.java
+++ b/java/vector/src/test/java/org/apache/arrow/vector/file/BaseFileTest.java
@@ -97,8 +97,14 @@ public class BaseFileTest {
 
   protected void validateContent(int count, VectorSchemaRoot root) {
     for (int i = 0; i < count; i++) {
-      Assert.assertEquals(i, root.getVector("int").getAccessor().getObject(i));
-      Assert.assertEquals(Long.valueOf(i), root.getVector("bigInt").getAccessor().getObject(i));
+      FieldVector fv = root.getVector("int");
+      if (fv instanceof NullableIntVector) {
+        Assert.assertEquals(i, fv.getObject(i));
+        Assert.assertEquals(Integer.valueOf(i), fv.getObject(i));
+      } else {
+        Assert.assertEquals(i, fv.getAccessor().getObject(i));
+        Assert.assertEquals(Long.valueOf(i), fv.getAccessor().getObject(i));
+      }
     }
   }
 
@@ -152,6 +158,7 @@ public class BaseFileTest {
     Assert.assertEquals(count, root.getRowCount());
     printVectors(root.getFieldVectors());
     for (int i = 0; i < count; i++) {
+
       Object intVal = root.getVector("int").getAccessor().getObject(i);
       if (i % 5 != 3) {
         Assert.assertEquals(i, intVal);
@@ -220,22 +227,20 @@ public class BaseFileTest {
     // Define dictionaries and add to provider
     NullableVarCharVector dictionary1Vector = newNullableVarCharVector("D1", bufferAllocator);
     dictionary1Vector.allocateNewSafe();
-    NullableVarCharVector.Mutator mutator = dictionary1Vector.getMutator();
-    mutator.set(0, "foo".getBytes(StandardCharsets.UTF_8));
-    mutator.set(1, "bar".getBytes(StandardCharsets.UTF_8));
-    mutator.set(2, "baz".getBytes(StandardCharsets.UTF_8));
-    mutator.setValueCount(3);
+    dictionary1Vector.set(0, "foo".getBytes(StandardCharsets.UTF_8));
+    dictionary1Vector.set(1, "bar".getBytes(StandardCharsets.UTF_8));
+    dictionary1Vector.set(2, "baz".getBytes(StandardCharsets.UTF_8));
+    dictionary1Vector.setValueCount(3);
 
     Dictionary dictionary1 = new Dictionary(dictionary1Vector, new DictionaryEncoding(1L, false, null));
     provider.put(dictionary1);
 
     NullableVarCharVector dictionary2Vector = newNullableVarCharVector("D2", bufferAllocator);
     dictionary2Vector.allocateNewSafe();
-    mutator = dictionary2Vector.getMutator();
-    mutator.set(0, "micro".getBytes(StandardCharsets.UTF_8));
-    mutator.set(1, "small".getBytes(StandardCharsets.UTF_8));
-    mutator.set(2, "large".getBytes(StandardCharsets.UTF_8));
-    mutator.setValueCount(3);
+    dictionary2Vector.set(0, "micro".getBytes(StandardCharsets.UTF_8));
+    dictionary2Vector.set(1, "small".getBytes(StandardCharsets.UTF_8));
+    dictionary2Vector.set(2, "large".getBytes(StandardCharsets.UTF_8));
+    dictionary2Vector.setValueCount(3);
 
     Dictionary dictionary2 = new Dictionary(dictionary2Vector, new DictionaryEncoding(2L, false, null));
     provider.put(dictionary2);
@@ -243,13 +248,12 @@ public class BaseFileTest {
     // Populate the vectors
     NullableVarCharVector vector1A = newNullableVarCharVector("varcharA", bufferAllocator);
     vector1A.allocateNewSafe();
-    mutator = vector1A.getMutator();
-    mutator.set(0, "foo".getBytes(StandardCharsets.UTF_8));
-    mutator.set(1, "bar".getBytes(StandardCharsets.UTF_8));
-    mutator.set(3, "baz".getBytes(StandardCharsets.UTF_8));
-    mutator.set(4, "bar".getBytes(StandardCharsets.UTF_8));
-    mutator.set(5, "baz".getBytes(StandardCharsets.UTF_8));
-    mutator.setValueCount(6);
+    vector1A.set(0, "foo".getBytes(StandardCharsets.UTF_8));
+    vector1A.set(1, "bar".getBytes(StandardCharsets.UTF_8));
+    vector1A.set(3, "baz".getBytes(StandardCharsets.UTF_8));
+    vector1A.set(4, "bar".getBytes(StandardCharsets.UTF_8));
+    vector1A.set(5, "baz".getBytes(StandardCharsets.UTF_8));
+    vector1A.setValueCount(6);
 
     FieldVector encodedVector1A = (FieldVector) DictionaryEncoder.encode(vector1A, dictionary1);
     vector1A.close();  // Done with this vector after encoding
@@ -257,22 +261,20 @@ public class BaseFileTest {
     // Write this vector using indices instead of encoding
     NullableIntVector encodedVector1B = new NullableIntVector("varcharB", bufferAllocator);
     encodedVector1B.allocateNewSafe();
-    NullableIntVector.Mutator mutator1B = encodedVector1B.getMutator();
-    mutator1B.set(0, 2);  // "baz"
-    mutator1B.set(1, 1);  // "bar"
-    mutator1B.set(2, 2);  // "baz"
-    mutator1B.set(4, 1);  // "bar"
-    mutator1B.set(5, 0);  // "foo"
-    mutator1B.setValueCount(6);
+    encodedVector1B.set(0, 2);  // "baz"
+    encodedVector1B.set(1, 1);  // "bar"
+    encodedVector1B.set(2, 2);  // "baz"
+    encodedVector1B.set(4, 1);  // "bar"
+    encodedVector1B.set(5, 0);  // "foo"
+    encodedVector1B.setValueCount(6);
 
     NullableVarCharVector vector2 = newNullableVarCharVector("sizes", bufferAllocator);
     vector2.allocateNewSafe();
-    mutator = vector2.getMutator();
-    mutator.set(1, "large".getBytes(StandardCharsets.UTF_8));
-    mutator.set(2, "small".getBytes(StandardCharsets.UTF_8));
-    mutator.set(3, "small".getBytes(StandardCharsets.UTF_8));
-    mutator.set(4, "large".getBytes(StandardCharsets.UTF_8));
-    mutator.setValueCount(6);
+    vector2.set(1, "large".getBytes(StandardCharsets.UTF_8));
+    vector2.set(2, "small".getBytes(StandardCharsets.UTF_8));
+    vector2.set(3, "small".getBytes(StandardCharsets.UTF_8));
+    vector2.set(4, "large".getBytes(StandardCharsets.UTF_8));
+    vector2.setValueCount(6);
 
     FieldVector encodedVector2 = (FieldVector) DictionaryEncoder.encode(vector2, dictionary2);
     vector2.close();  // Done with this vector after encoding
@@ -355,8 +357,8 @@ public class BaseFileTest {
     // Define the dictionary and add to the provider
     NullableVarCharVector dictionaryVector = newNullableVarCharVector("D2", bufferAllocator);
     dictionaryVector.allocateNewSafe();
-    dictionaryVector.getMutator().set(0, "foo".getBytes(StandardCharsets.UTF_8));
-    dictionaryVector.getMutator().set(1, "bar".getBytes(StandardCharsets.UTF_8));
+    dictionaryVector.set(0, "foo".getBytes(StandardCharsets.UTF_8));
+    dictionaryVector.set(1, "bar".getBytes(StandardCharsets.UTF_8));
     dictionaryVector.getMutator().setValueCount(2);
 
     Dictionary dictionary = new Dictionary(dictionaryVector, new DictionaryEncoding(2L, false, null));

http://git-wip-us.apache.org/repos/asf/arrow/blob/60a2ebdf/java/vector/src/test/java/org/apache/arrow/vector/file/TestArrowFile.java
----------------------------------------------------------------------
diff --git a/java/vector/src/test/java/org/apache/arrow/vector/file/TestArrowFile.java b/java/vector/src/test/java/org/apache/arrow/vector/file/TestArrowFile.java
index 81e5898..feae08e 100644
--- a/java/vector/src/test/java/org/apache/arrow/vector/file/TestArrowFile.java
+++ b/java/vector/src/test/java/org/apache/arrow/vector/file/TestArrowFile.java
@@ -581,7 +581,7 @@ public class TestArrowFile extends BaseFileTest {
         tuples.getMutator().setNotNull(i);
         floats.getMutator().set(i * 2, i + 0.1f);
         floats.getMutator().set(i * 2 + 1, i + 10.1f);
-        ints.getMutator().set(i, i);
+        ints.set(i, i);
       }
 
       parent.getMutator().setValueCount(10);


Mime
View raw message