use of org.apache.drill.exec.vector.NullableVarCharVector in project drill by axbaretto.
the class TestVectorLimits method testNullableWideVariableVector.
@Test
public void testNullableWideVariableVector() {
@SuppressWarnings("resource") NullableVarCharVector vector = new NullableVarCharVector(makeField(MinorType.VARCHAR, DataMode.OPTIONAL), fixture.allocator());
vector.allocateNew();
byte[] dummyValue = makeVarCharValue(512);
NullableVarCharVector.Mutator mutator = vector.getMutator();
int count = 0;
for (; count < 2 * ValueVector.MAX_ROW_COUNT; count++) {
try {
mutator.setScalar(count, dummyValue, 0, dummyValue.length);
} catch (VectorOverflowException e) {
break;
}
}
mutator.setValueCount(count);
assertEquals(ValueVector.MAX_BUFFER_SIZE, vector.getValuesVector().getBuffer().getActualMemoryConsumed());
assertTrue(count < ValueVector.MAX_ROW_COUNT);
vector.close();
}
use of org.apache.drill.exec.vector.NullableVarCharVector in project drill by axbaretto.
the class TestValueVector method testReAllocNullableVariableWidthVector.
@Test
public void testReAllocNullableVariableWidthVector() {
final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, NullableVarCharHolder.TYPE);
// Create a new value vector for 1024 integers
try (final NullableVarCharVector vector = (NullableVarCharVector) TypeHelper.getNewVector(field, allocator)) {
final NullableVarCharVector.Mutator m = vector.getMutator();
vector.allocateNew();
int initialCapacity = vector.getValueCapacity();
// Put values in indexes that fall within the initial allocation
m.setSafe(0, STR1, 0, STR1.length);
m.setSafe(initialCapacity - 1, STR2, 0, STR2.length);
// Now try to put values in space that falls beyond the initial allocation
m.setSafe(initialCapacity + 200, STR3, 0, STR3.length);
// Check valueCapacity is more than initial allocation
assertEquals((initialCapacity + 1) * 2 - 1, vector.getValueCapacity());
final NullableVarCharVector.Accessor accessor = vector.getAccessor();
assertArrayEquals(STR1, accessor.get(0));
assertArrayEquals(STR2, accessor.get(initialCapacity - 1));
assertArrayEquals(STR3, accessor.get(initialCapacity + 200));
// Set the valueCount to be more than valueCapacity of current allocation. This is possible for NullableValueVectors
// as we don't call setSafe for null values, but we do call setValueCount when the current batch is processed.
m.setValueCount(vector.getValueCapacity() + 200);
}
}
use of org.apache.drill.exec.vector.NullableVarCharVector in project drill by apache.
the class TestToNullable method testVariableWidth.
@Test
public void testVariableWidth() {
MaterializedField nonNullableSchema = SchemaBuilder.columnSchema("a", MinorType.VARCHAR, DataMode.REQUIRED);
@SuppressWarnings("resource") VarCharVector nonNullableVector = new VarCharVector(nonNullableSchema, fixture.allocator());
VarCharVector.Mutator mutator = nonNullableVector.getMutator();
nonNullableVector.allocateNew(100, 20);
byte[] value = new byte[20];
for (int i = 0; i < 100; i++) {
Arrays.fill(value, (byte) ('A' + i % 26));
mutator.setSafe(i, value);
}
mutator.setValueCount(100);
MaterializedField nullableVarCharSchema = SchemaBuilder.columnSchema("a", MinorType.VARCHAR, DataMode.OPTIONAL);
NullableVarCharVector nullableVector = new NullableVarCharVector(nullableVarCharSchema, fixture.allocator());
nonNullableVector.toNullable(nullableVector);
assertEquals(0, nonNullableVector.getAccessor().getValueCount());
NullableVarCharVector.Accessor nullableAccessor = nullableVector.getAccessor();
assertEquals(100, nullableAccessor.getValueCount());
for (int i = 0; i < 100; i++) {
assertFalse(nullableAccessor.isNull(i));
Arrays.fill(value, (byte) ('A' + i % 26));
assertTrue(Arrays.areEqual(value, nullableAccessor.get(i)));
}
nullableVector.clear();
// Don't clear the nonNullableVector, it should be empty.
// If it is not, the test will fail with a memory leak error.
}
use of org.apache.drill.exec.vector.NullableVarCharVector in project drill by apache.
the class TestFillEmpties method testNullableVarChar.
@Test
public void testNullableVarChar() {
NullableVarCharVector vector = new NullableVarCharVector(SchemaBuilder.columnSchema("a", MinorType.VARCHAR, DataMode.OPTIONAL), fixture.allocator());
vector.allocateNew();
// Create "foo", null, "bar", but omit the null.
NullableVarCharVector.Mutator mutator = vector.getMutator();
byte[] value = makeValue("foo");
mutator.setSafe(0, value, 0, value.length);
value = makeValue("bar");
mutator.setSafe(2, value, 0, value.length);
visualize(vector, 3);
verifyOffsets(vector.getValuesVector().getOffsetVector(), new int[] { 0, 3, 3, 6 });
vector.close();
}
use of org.apache.drill.exec.vector.NullableVarCharVector in project drill by apache.
the class TestSimpleFunctions method testSubstringNegative.
@Test
public void testSubstringNegative() throws Throwable {
final DrillbitContext bitContext = mockDrillbitContext();
final UserClientConnection connection = Mockito.mock(UserClientConnection.class);
final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
final PhysicalPlan plan = reader.readPhysicalPlan(Files.asCharSource(DrillFileUtils.getResourceAsFile("/functions/testSubstringNegative.json"), Charsets.UTF_8).read());
final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
while (exec.next()) {
final NullableVarCharVector c1 = exec.getValueVectorById(new SchemaPath("col3", ExpressionPosition.UNKNOWN), NullableVarCharVector.class);
final NullableVarCharVector.Accessor a1 = c1.getAccessor();
int count = 0;
for (int i = 0; i < c1.getAccessor().getValueCount(); i++) {
if (!a1.isNull(i)) {
final NullableVarCharHolder holder = new NullableVarCharHolder();
a1.get(i, holder);
// when offset is negative, substring return empty string.
assertEquals("", StringFunctionHelpers.toStringFromUTF8(holder.start, holder.end, holder.buffer));
++count;
}
}
assertEquals(50, count);
}
if (context.getExecutorState().getFailureCause() != null) {
throw context.getExecutorState().getFailureCause();
}
assertTrue(!context.getExecutorState().isFailed());
}
Aggregations