forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Closes apache#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
- Loading branch information
1 parent
d235f69
commit 20b7148
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
java/vector/src/test/java/org/apache/arrow/vector/TestVectorSchemaRoot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |