use of org.apache.drill.exec.vector.NullableVarCharVector in project drill by axbaretto.
the class TestValueVector method testNullableVarCharVectorLoad.
@Test
public void testNullableVarCharVectorLoad() {
final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, NullableVarCharHolder.TYPE);
// Create a new value vector for 1024 nullable variable length strings.
@SuppressWarnings("resource") final NullableVarCharVector vector1 = new NullableVarCharVector(field, allocator);
final NullableVarCharVector.Mutator mutator = vector1.getMutator();
vector1.allocateNew(1024 * 10, 1024);
// Populate the vector.
final StringBuilder stringBuilder = new StringBuilder();
final int valueCount = 10;
for (int i = 0; i < valueCount; ++i) {
stringBuilder.append('x');
mutator.set(i, stringBuilder.toString().getBytes(utf8Charset));
}
// Check the contents.
final NullableVarCharVector.Accessor accessor1 = vector1.getAccessor();
stringBuilder.setLength(0);
for (int i = 0; i < valueCount; ++i) {
stringBuilder.append('x');
final Object object = accessor1.getObject(i);
assertEquals(stringBuilder.toString(), object.toString());
}
mutator.setValueCount(valueCount);
assertEquals(valueCount, vector1.getAccessor().getValueCount());
// Still ok after setting value count?
stringBuilder.setLength(0);
for (int i = 0; i < valueCount; ++i) {
stringBuilder.append('x');
final Object object = accessor1.getObject(i);
assertEquals(stringBuilder.toString(), object.toString());
}
// Combine into a single buffer so we can load it into a new vector.
final DrillBuf[] buffers1 = vector1.getBuffers(false);
@SuppressWarnings("resource") final DrillBuf buffer1 = combineBuffers(allocator, buffers1);
@SuppressWarnings("resource") final NullableVarCharVector vector2 = new NullableVarCharVector(field, allocator);
vector2.load(vector1.getMetadata(), buffer1);
// Check the vector's contents.
final NullableVarCharVector.Accessor accessor2 = vector2.getAccessor();
stringBuilder.setLength(0);
for (int i = 0; i < valueCount; ++i) {
stringBuilder.append('x');
final Object object = accessor2.getObject(i);
assertEquals(stringBuilder.toString(), object.toString());
}
vector1.close();
vector2.close();
buffer1.release();
}
use of org.apache.drill.exec.vector.NullableVarCharVector in project drill by axbaretto.
the class TestValueVector method testNullableVarLen2.
@Test
public void testNullableVarLen2() {
final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, NullableVarCharHolder.TYPE);
// Create a new value vector for 1024 integers.
try (final NullableVarCharVector vector = new NullableVarCharVector(field, allocator)) {
final NullableVarCharVector.Mutator m = vector.getMutator();
vector.allocateNew(1024 * 10, 1024);
m.set(0, STR1);
m.set(1, STR2);
m.set(2, STR3);
// Check the sample strings.
final NullableVarCharVector.Accessor accessor = vector.getAccessor();
assertArrayEquals(STR1, accessor.get(0));
assertArrayEquals(STR2, accessor.get(1));
assertArrayEquals(STR3, accessor.get(2));
// Ensure null value throws.
boolean b = false;
try {
vector.getAccessor().get(3);
} catch (IllegalStateException e) {
b = true;
} finally {
assertTrue(b);
}
}
}
use of org.apache.drill.exec.vector.NullableVarCharVector in project drill by axbaretto.
the class TestFillEmpties method testNullableVarChar.
@Test
public void testNullableVarChar() {
@SuppressWarnings("resource") 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 axbaretto.
the class TestToNullable method testVariableWidth.
@SuppressWarnings("resource")
@Test
public void testVariableWidth() {
MaterializedField nonNullableSchema = SchemaBuilder.columnSchema("a", MinorType.VARCHAR, DataMode.REQUIRED);
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 axbaretto.
the class TestVectorLimits method testDirectNullableVariableVector.
@Test
public void testDirectNullableVariableVector() {
@SuppressWarnings("resource") NullableVarCharVector vector = new NullableVarCharVector(makeField(MinorType.VARCHAR, DataMode.OPTIONAL), fixture.allocator());
vector.allocateNew();
@SuppressWarnings("resource") DrillBuf drillBuf = makeVarCharValueDirect(260);
NullableVarCharVector.Mutator mutator = vector.getMutator();
int count = 0;
for (; count < 2 * ValueVector.MAX_ROW_COUNT; count++) {
try {
mutator.setScalar(count, drillBuf, 0, 260);
} catch (VectorOverflowException e) {
break;
}
}
drillBuf.close();
mutator.setValueCount(count);
assertEquals(ValueVector.MAX_BUFFER_SIZE, vector.getValuesVector().getBuffer().getActualMemoryConsumed());
assertTrue(count < ValueVector.MAX_ROW_COUNT);
vector.close();
}
Aggregations