Search in sources :

Example 11 with NullableIntVector

use of org.apache.drill.exec.vector.NullableIntVector in project drill by apache.

the class TestToNullable method testNullable.

@Test
public void testNullable() {
    MaterializedField nullableIntSchema = SchemaBuilder.columnSchema("a", MinorType.INT, DataMode.OPTIONAL);
    @SuppressWarnings("resource") NullableIntVector sourceVector = new NullableIntVector(nullableIntSchema, fixture.allocator());
    NullableIntVector.Mutator sourceMutator = sourceVector.getMutator();
    sourceVector.allocateNew(100);
    for (int i = 0; i < 100; i++) {
        sourceMutator.set(i, i * 10);
    }
    sourceMutator.setValueCount(100);
    NullableIntVector destVector = new NullableIntVector(nullableIntSchema, fixture.allocator());
    sourceVector.toNullable(destVector);
    assertEquals(0, sourceVector.getAccessor().getValueCount());
    NullableIntVector.Accessor destAccessor = destVector.getAccessor();
    assertEquals(100, destAccessor.getValueCount());
    for (int i = 0; i < 100; i++) {
        assertFalse(destAccessor.isNull(i));
        assertEquals(i * 10, destAccessor.get(i));
    }
    destVector.clear();
// Don't clear the intVector, it should be empty.
// If it is not, the test will fail with a memory leak error.
}
Also used : NullableIntVector(org.apache.drill.exec.vector.NullableIntVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

NullableIntVector (org.apache.drill.exec.vector.NullableIntVector)11 Test (org.junit.Test)8 SubOperatorTest (org.apache.drill.test.SubOperatorTest)7 NullableBigIntVector (org.apache.drill.exec.vector.NullableBigIntVector)5 NullableVarCharVector (org.apache.drill.exec.vector.NullableVarCharVector)5 MaterializedField (org.apache.drill.exec.record.MaterializedField)4 NullableFloat8Vector (org.apache.drill.exec.vector.NullableFloat8Vector)4 SchemaPath (org.apache.drill.common.expression.SchemaPath)3 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)3 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)3 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)3 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)3 NullableDateVector (org.apache.drill.exec.vector.NullableDateVector)3 NullableFloat4Vector (org.apache.drill.exec.vector.NullableFloat4Vector)3 NullableSmallIntVector (org.apache.drill.exec.vector.NullableSmallIntVector)3 NullableTimeStampVector (org.apache.drill.exec.vector.NullableTimeStampVector)3 NullableTimeVector (org.apache.drill.exec.vector.NullableTimeVector)3 NullableTinyIntVector (org.apache.drill.exec.vector.NullableTinyIntVector)3 NullableUInt1Vector (org.apache.drill.exec.vector.NullableUInt1Vector)3 NullableUInt2Vector (org.apache.drill.exec.vector.NullableUInt2Vector)3