Search in sources :

Example 6 with NullableVarCharVector

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();
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) DrillBuf(io.netty.buffer.DrillBuf) VectorTest(org.apache.drill.categories.VectorTest) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Example 7 with NullableVarCharVector

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);
        }
    }
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) VectorTest(org.apache.drill.categories.VectorTest) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Example 8 with NullableVarCharVector

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();
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test) VectorTest(org.apache.drill.categories.VectorTest)

Example 9 with NullableVarCharVector

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.
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) VarCharVector(org.apache.drill.exec.vector.VarCharVector) NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 10 with NullableVarCharVector

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();
}
Also used : NullableVarCharVector(org.apache.drill.exec.vector.NullableVarCharVector) VectorOverflowException(org.apache.drill.exec.vector.VectorOverflowException) DrillBuf(io.netty.buffer.DrillBuf) Test(org.junit.Test) VectorTest(org.apache.drill.categories.VectorTest) DrillTest(org.apache.drill.test.DrillTest)

Aggregations

NullableVarCharVector (org.apache.drill.exec.vector.NullableVarCharVector)33 Test (org.junit.Test)25 ExecTest (org.apache.drill.exec.ExecTest)12 VectorTest (org.apache.drill.categories.VectorTest)10 MaterializedField (org.apache.drill.exec.record.MaterializedField)10 SchemaPath (org.apache.drill.common.expression.SchemaPath)9 VarCharVector (org.apache.drill.exec.vector.VarCharVector)9 SubOperatorTest (org.apache.drill.test.SubOperatorTest)9 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)6 ValueVector (org.apache.drill.exec.vector.ValueVector)6 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)5 NullableVarCharHolder (org.apache.drill.exec.expr.holders.NullableVarCharHolder)5 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)5 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)5 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)5 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)5 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)5 NullableBigIntVector (org.apache.drill.exec.vector.NullableBigIntVector)5 NullableIntVector (org.apache.drill.exec.vector.NullableIntVector)5 NullableUInt4Vector (org.apache.drill.exec.vector.NullableUInt4Vector)5