Repository: arrow
Updated Branches:
  refs/heads/master f00e2ab59 -> 1a73c352d


ARROW-895: Fix lastSet in fillEmpties() and copyFrom()

Author: Steven Phillips <ste...@dremio.com>

Closes #601 from StevenMPhillips/fillEmpties4 and squashes the following 
commits:

4707673 [Steven Phillips] ARROW-895: Fix lastSet in fillEmpties() and copyFrom()


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

Branch: refs/heads/master
Commit: 1a73c352d023dfa0e8aca4c16f3e421745524ea8
Parents: f00e2ab
Author: Steven Phillips <ste...@dremio.com>
Authored: Tue Apr 25 11:25:03 2017 -0700
Committer: Julien Le Dem <jul...@apache.org>
Committed: Tue Apr 25 11:25:03 2017 -0700

----------------------------------------------------------------------
 .../codegen/templates/NullableValueVectors.java |  5 ++-
 .../apache/arrow/vector/TestValueVector.java    | 38 ++++++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/1a73c352/java/vector/src/main/codegen/templates/NullableValueVectors.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/NullableValueVectors.java 
b/java/vector/src/main/codegen/templates/NullableValueVectors.java
index 178d5bd..31adc2b 100644
--- a/java/vector/src/main/codegen/templates/NullableValueVectors.java
+++ b/java/vector/src/main/codegen/templates/NullableValueVectors.java
@@ -393,6 +393,7 @@ public final class ${className} extends BaseDataValueVector 
implements <#if type
     if (!fromAccessor.isNull(fromIndex)) {
       mutator.set(thisIndex, fromAccessor.get(fromIndex));
     }
+    <#if type.major == "VarLen">mutator.lastSet = thisIndex;</#if>
   }
 
   public void copyFromSafe(int fromIndex, int thisIndex, ${valuesName} from){
@@ -401,6 +402,7 @@ public final class ${className} extends BaseDataValueVector 
implements <#if type
     </#if>
     values.copyFromSafe(fromIndex, thisIndex, from);
     bits.getMutator().setSafeToOne(thisIndex);
+    <#if type.major == "VarLen">mutator.lastSet = thisIndex;</#if>
   }
 
   public void copyFromSafe(int fromIndex, int thisIndex, ${className} from){
@@ -409,6 +411,7 @@ public final class ${className} extends BaseDataValueVector 
implements <#if type
     </#if>
     bits.copyFromSafe(fromIndex, thisIndex, from.bits);
     values.copyFromSafe(fromIndex, thisIndex, from.values);
+    <#if type.major == "VarLen">mutator.lastSet = thisIndex;</#if>
   }
 
   public final class Accessor extends BaseDataValueVector.BaseAccessor <#if 
type.major = "VarLen">implements 
VariableWidthVector.VariableWidthAccessor</#if> {
@@ -532,7 +535,7 @@ public final class ${className} extends BaseDataValueVector 
implements <#if type
       while(index > bits.getValueCapacity()) {
         bits.reAlloc();
       }
-      lastSet = index;
+      lastSet = index - 1;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/arrow/blob/1a73c352/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 e6e49ab..63543b0 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
@@ -21,6 +21,7 @@ import static 
org.apache.arrow.vector.TestUtils.newNullableVarCharVector;
 import static org.apache.arrow.vector.TestUtils.newVector;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.nio.charset.Charset;
@@ -473,9 +474,46 @@ public class TestValueVector {
 
       vector.getMutator().setSafe(4094, "hello".getBytes(), 0, 5);
       vector.getMutator().setValueCount(4095);
+
       assertEquals(4096 * 4, vector.getFieldBuffers().get(1).capacity());
     }
   }
 
+  @Test
+  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();
+
+      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.getMutator().setValueCount(4095);
+
+      vector2.allocateNew();
+
+      for (int i = 0; i < 4095; i++) {
+        vector2.copyFromSafe(i, i, vector);
+      }
+
+      vector2.getMutator().setValueCount(4095);
+
+      for (int i = 0; i < 4095; i++) {
+        if (i % 3 == 0) {
+          assertNull(vector2.getAccessor().getObject(i));
+        } else {
+          assertEquals(Integer.toString(i), 
vector2.getAccessor().getObject(i).toString());
+        }
+
+      }
+
+
+    }
+  }
 
 }

Reply via email to