You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by cu...@apache.org on 2019/06/06 20:16:09 UTC

[arrow] branch master updated: ARROW-5518: [Java] Set VectorSchemaRoot rowCount to 0 on allocateNew and clear

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

cutlerb 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 20b7148  ARROW-5518: [Java] Set VectorSchemaRoot rowCount to 0 on allocateNew and clear
20b7148 is described below

commit 20b714899c49c31457db73602c12d65cff77599f
Author: Johannes Luong <jo...@gmail.com>
AuthorDate: Thu Jun 6 13:15:48 2019 -0700

    ARROW-5518: [Java] Set VectorSchemaRoot rowCount to 0 on allocateNew and clear
    
    Set VectorSchemaRoot::rowCount to 0 in allocateNew() and clear(). This makes the behaviour of VectorSchemaRoot consistent with ValueVector implementations which set their valueCount to 0 on clear().
    
    Author: Johannes Luong <jo...@gmail.com>
    
    Closes #4481 from jmaschad/master and squashes the following commits:
    
    3570c96 <Johannes Luong> Remove unused variable
    1a38403 <Johannes Luong> Test clear as well
    5cdffe0 <Johannes Luong> Reset VectorSchemaRoot row count
---
 .../org/apache/arrow/vector/VectorSchemaRoot.java  |  2 +
 .../apache/arrow/vector/TestVectorSchemaRoot.java  | 78 ++++++++++++++++++++++
 2 files changed, 80 insertions(+)

diff --git a/java/vector/src/main/java/org/apache/arrow/vector/VectorSchemaRoot.java b/java/vector/src/main/java/org/apache/arrow/vector/VectorSchemaRoot.java
index a94bdfc..373e03c 100644
--- a/java/vector/src/main/java/org/apache/arrow/vector/VectorSchemaRoot.java
+++ b/java/vector/src/main/java/org/apache/arrow/vector/VectorSchemaRoot.java
@@ -121,6 +121,7 @@ public class VectorSchemaRoot implements AutoCloseable {
     for (FieldVector v : fieldVectors) {
       v.allocateNew();
     }
+    rowCount = 0;
   }
 
   /**
@@ -130,6 +131,7 @@ public class VectorSchemaRoot implements AutoCloseable {
     for (FieldVector v : fieldVectors) {
       v.clear();
     }
+    rowCount = 0;
   }
 
   public List<FieldVector> getFieldVectors() {
diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestVectorSchemaRoot.java b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorSchemaRoot.java
new file mode 100644
index 0000000..480dcac
--- /dev/null
+++ b/java/vector/src/test/java/org/apache/arrow/vector/TestVectorSchemaRoot.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.arrow.vector;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.RootAllocator;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestVectorSchemaRoot {
+  private BufferAllocator allocator;
+
+  @Before
+  public void init() {
+    allocator = new RootAllocator(Long.MAX_VALUE);
+  }
+
+  @After
+  public void terminate() {
+    allocator.close();
+  }
+
+  @Test
+  public void testResetRowCount() {
+    final int size = 20;
+    try (final BitVector vec1 = new BitVector("bit", allocator);
+         final IntVector vec2 = new IntVector("int", allocator)) {
+      VectorSchemaRoot vsr = VectorSchemaRoot.of(vec1, vec2);
+
+      vsr.allocateNew();
+      assertEquals(vsr.getRowCount(), 0);
+
+      for (int i = 0; i < size; i++) {
+        vec1.setSafe(i, i % 2);
+        vec2.setSafe(i, i);
+      }
+      vsr.setRowCount(size);
+      checkCount(vec1, vec2, vsr, size);
+
+      vsr.allocateNew();
+      checkCount(vec1, vec2, vsr, 0);
+
+      for (int i = 0; i < size; i++) {
+        vec1.setSafe(i, i % 2);
+        vec2.setSafe(i, i);
+      }
+      vsr.setRowCount(size);
+      checkCount(vec1, vec2, vsr, size);
+
+      vsr.clear();
+      checkCount(vec1, vec2, vsr, 0);
+    }
+  }
+
+  private void checkCount(BitVector vec1, IntVector vec2, VectorSchemaRoot vsr, int count) {
+    assertEquals(vec1.getValueCount(), count);
+    assertEquals(vec2.getValueCount(), count);
+    assertEquals(vsr.getRowCount(), count);
+  }
+}