Search in sources :

Example 6 with NullableFloat4Vector

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

the class TestValueVector method testNullableFloat.

@Test
public void testNullableFloat() {
    final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, NullableFloat4Holder.TYPE);
    // Create a new value vector for 1024 integers
    try (final NullableFloat4Vector vector = (NullableFloat4Vector) TypeHelper.getNewVector(field, allocator)) {
        final NullableFloat4Vector.Mutator m = vector.getMutator();
        vector.allocateNew(1024);
        // Put and set a few values.
        m.set(0, 100.1f);
        m.set(1, 101.2f);
        m.set(100, 102.3f);
        m.set(1022, 103.4f);
        m.set(1023, 104.5f);
        final NullableFloat4Vector.Accessor accessor = vector.getAccessor();
        assertEquals(100.1f, accessor.get(0), 0);
        assertEquals(101.2f, accessor.get(1), 0);
        assertEquals(102.3f, accessor.get(100), 0);
        assertEquals(103.4f, accessor.get(1022), 0);
        assertEquals(104.5f, accessor.get(1023), 0);
        // Ensure null values throw.
        {
            boolean b = false;
            try {
                vector.getAccessor().get(3);
            } catch (IllegalStateException e) {
                b = true;
            } finally {
                assertTrue(b);
            }
        }
        vector.allocateNew(2048);
        {
            boolean b = false;
            try {
                accessor.get(0);
            } catch (IllegalStateException e) {
                b = true;
            } finally {
                assertTrue(b);
            }
        }
    }
}
Also used : NullableFloat4Vector(org.apache.drill.exec.vector.NullableFloat4Vector) 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 7 with NullableFloat4Vector

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

the class TestValueVector method testReAllocNullableFixedWidthVector.

@Test
public void testReAllocNullableFixedWidthVector() {
    final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, NullableFloat4Holder.TYPE);
    // Create a new value vector for 1024 integers
    try (final NullableFloat4Vector vector = (NullableFloat4Vector) TypeHelper.getNewVector(field, allocator)) {
        final NullableFloat4Vector.Mutator m = vector.getMutator();
        vector.allocateNew(1024);
        assertEquals(1024, vector.getValueCapacity());
        // Put values in indexes that fall within the initial allocation
        m.setSafe(0, 100.1f);
        m.setSafe(100, 102.3f);
        m.setSafe(1023, 104.5f);
        // Now try to put values in space that falls beyond the initial allocation
        m.setSafe(2000, 105.5f);
        // Check valueCapacity is more than initial allocation
        assertEquals(1024 * 2, vector.getValueCapacity());
        final NullableFloat4Vector.Accessor accessor = vector.getAccessor();
        assertEquals(100.1f, accessor.get(0), 0);
        assertEquals(102.3f, accessor.get(100), 0);
        assertEquals(104.5f, accessor.get(1023), 0);
        assertEquals(105.5f, accessor.get(2000), 0);
        // 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 all values are inserted into the
        // vector
        m.setValueCount(vector.getValueCapacity() + 200);
    }
}
Also used : NullableFloat4Vector(org.apache.drill.exec.vector.NullableFloat4Vector) 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)

Aggregations

NullableFloat4Vector (org.apache.drill.exec.vector.NullableFloat4Vector)7 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)4 VectorTest (org.apache.drill.categories.VectorTest)4 ExecTest (org.apache.drill.exec.ExecTest)4 MaterializedField (org.apache.drill.exec.record.MaterializedField)4 Test (org.junit.Test)4 SchemaPath (org.apache.drill.common.expression.SchemaPath)3 NullableBigIntVector (org.apache.drill.exec.vector.NullableBigIntVector)3 NullableDateVector (org.apache.drill.exec.vector.NullableDateVector)3 NullableFloat8Vector (org.apache.drill.exec.vector.NullableFloat8Vector)3 NullableIntVector (org.apache.drill.exec.vector.NullableIntVector)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 NullableUInt4Vector (org.apache.drill.exec.vector.NullableUInt4Vector)3 NullableVarBinaryVector (org.apache.drill.exec.vector.NullableVarBinaryVector)3 NullableVarCharVector (org.apache.drill.exec.vector.NullableVarCharVector)3