Skip to content

Commit

Permalink
ARROW-886 Fixing reallocation of VariableLengthVector offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
elahrvivaz committed Apr 24, 2017
1 parent 95f489c commit 5f6b4be
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ public void reset() {
}

public void reAlloc() {
offsetVector.reAlloc();
final long newAllocationSize = allocationSizeInBytes*2L;
if (newAllocationSize > MAX_ALLOCATION_SIZE) {
throw new OversizedAllocationException("Unable to expand the buffer. Max allowed buffer size is reached.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,31 @@ public void testFixedType() {
}
}

@Test
public void testVariableLengthType() {
try (final VarCharVector vector = new VarCharVector("", allocator)) {
final VarCharVector.Mutator m = vector.getMutator();
// note: capacity ends up being - 1 due to offsets vector
vector.setInitialCapacity(511);
vector.allocateNew();

assertEquals(511, vector.getValueCapacity());

try {
m.set(512, "foo".getBytes(StandardCharsets.UTF_8));
Assert.fail("Expected out of bounds exception");
} catch (Exception e) {
// ok
}

vector.reAlloc();
assertEquals(1023, vector.getValueCapacity());

m.set(512, "foo".getBytes(StandardCharsets.UTF_8));
assertEquals("foo", new String(vector.getAccessor().get(512), StandardCharsets.UTF_8));
}
}

@Test
public void testNullableType() {
try (final NullableVarCharVector vector = new NullableVarCharVector("", allocator)) {
Expand All @@ -89,7 +114,7 @@ public void testNullableType() {
}

vector.reAlloc();
assertEquals(1023, vector.getValueCapacity()); // note: size - 1 for some reason...
assertEquals(1024, vector.getValueCapacity());

m.set(512, "foo".getBytes(StandardCharsets.UTF_8));
assertEquals("foo", new String(vector.getAccessor().get(512), StandardCharsets.UTF_8));
Expand Down

0 comments on commit 5f6b4be

Please sign in to comment.