Repository: arrow Updated Branches: refs/heads/master e968ca6e3 -> dcaa8e5d7
ARROW-702: fix BitVector.copyFromSafe to reAllocate instead of returning false Author: Julien Le Dem <jul...@dremio.com> Closes #426 from julienledem/arrow_702 and squashes the following commits: 4c77b95 [Julien Le Dem] add license 7ab84aa [Julien Le Dem] Thanks Hakim for the test case ba8aa8e [Julien Le Dem] ARROW-702: fix BitVector.copyFromSafe to reAllocate instead of returning false Project: http://git-wip-us.apache.org/repos/asf/arrow/repo Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/dcaa8e5d Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/dcaa8e5d Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/dcaa8e5d Branch: refs/heads/master Commit: dcaa8e5d7ef1353c657e016bf271495042825a91 Parents: e968ca6 Author: Julien Le Dem <jul...@dremio.com> Authored: Thu Mar 23 12:44:27 2017 -0700 Committer: Julien Le Dem <jul...@dremio.com> Committed: Thu Mar 23 12:44:27 2017 -0700 ---------------------------------------------------------------------- .../apache/arrow/memory/TestBaseAllocator.java | 2 +- .../java/org/apache/arrow/vector/BitVector.java | 8 +-- .../org/apache/arrow/vector/TestBitVector.java | 66 ++++++++++++++++++++ 3 files changed, 70 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/arrow/blob/dcaa8e5d/java/memory/src/test/java/org/apache/arrow/memory/TestBaseAllocator.java ---------------------------------------------------------------------- diff --git a/java/memory/src/test/java/org/apache/arrow/memory/TestBaseAllocator.java b/java/memory/src/test/java/org/apache/arrow/memory/TestBaseAllocator.java index 3c96d57..59b7be8 100644 --- a/java/memory/src/test/java/org/apache/arrow/memory/TestBaseAllocator.java +++ b/java/memory/src/test/java/org/apache/arrow/memory/TestBaseAllocator.java @@ -381,7 +381,7 @@ public class TestBaseAllocator { assertEquals((byte) i, slice1.getByte(i)); } - final ArrowBuf slice2 = (ArrowBuf) arrowBuf.slice(25, 25); + final ArrowBuf slice2 = arrowBuf.slice(25, 25); assertEquals(0, slice2.readerIndex()); assertEquals(25, slice2.readableBytes()); for(int i = 25; i < 50; ++i) { http://git-wip-us.apache.org/repos/asf/arrow/blob/dcaa8e5d/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java ---------------------------------------------------------------------- diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java index 179f2ee..ed57433 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BitVector.java @@ -216,13 +216,11 @@ public final class BitVector extends BaseDataValueVector implements FixedWidthVe this.mutator.set(outIndex, from.accessor.get(inIndex)); } - public boolean copyFromSafe(int inIndex, int outIndex, BitVector from) { + public void copyFromSafe(int inIndex, int outIndex, BitVector from) { if (outIndex >= this.getValueCapacity()) { - decrementAllocationMonitor(); - return false; + reAlloc(); } copyFrom(inIndex, outIndex, from); - return true; } @Override @@ -273,7 +271,7 @@ public final class BitVector extends BaseDataValueVector implements FixedWidthVe if (target.data != null) { target.data.release(); } - target.data = (ArrowBuf) data.slice(firstByte, byteSize); + target.data = data.slice(firstByte, byteSize); target.data.retain(1); } else { // Copy data http://git-wip-us.apache.org/repos/asf/arrow/blob/dcaa8e5d/java/vector/src/test/java/org/apache/arrow/vector/TestBitVector.java ---------------------------------------------------------------------- diff --git a/java/vector/src/test/java/org/apache/arrow/vector/TestBitVector.java b/java/vector/src/test/java/org/apache/arrow/vector/TestBitVector.java new file mode 100644 index 0000000..f2343c8 --- /dev/null +++ b/java/vector/src/test/java/org/apache/arrow/vector/TestBitVector.java @@ -0,0 +1,66 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class TestBitVector { + private final static String EMPTY_SCHEMA_PATH = ""; + + private BufferAllocator allocator; + + @Before + public void init() { + allocator = new DirtyRootAllocator(Long.MAX_VALUE, (byte) 100); + } + + @After + public void terminate() throws Exception { + allocator.close(); + } + + @Test + public void testBitVectorCopyFromSafe() { + final int size = 20; + try (final BitVector src = new BitVector(EMPTY_SCHEMA_PATH, allocator); + final BitVector dst = new BitVector(EMPTY_SCHEMA_PATH, allocator)) { + src.allocateNew(size); + dst.allocateNew(10); + + for (int i = 0; i < size; i++) { + src.getMutator().set(i, i % 2); + } + src.getMutator().setValueCount(size); + + for (int i = 0; i < size; i++) { + dst.copyFromSafe(i, i, src); + } + dst.getMutator().setValueCount(size); + + for (int i = 0; i < size; i++) { + assertEquals(src.getAccessor().getObject(i), dst.getAccessor().getObject(i)); + } + } + } + +}