Search in sources :

Example 61 with IntVector

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

the class TestFixedWidthWriter method testRolloverWithEmpties.

/**
 * Simulate the case in which the tail end of an overflow
 * batch has empties. <tt>preRollover()</tt> should back-fill
 * them with the next offset prior to rollover.
 */
@Test
public void testRolloverWithEmpties() {
    try (IntVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        IntColumnWriter writer = makeWriter(vector, index);
        writer.startWrite();
        for (int i = 0; i < 10; i++) {
            index.index = i;
            writer.startRow();
            writer.setInt(i);
            writer.saveRow();
        }
        for (int i = 10; i < 15; i++) {
            index.index = i;
            writer.startRow();
            writer.saveRow();
        }
        // Overflow occurs before writing the 16th row
        index.index = 15;
        writer.startRow();
        // Overflow occurs. This should fill empty offsets.
        writer.preRollover();
        for (int i = 0; i < 10; i++) {
            assertEquals(i, vector.getAccessor().get(i));
        }
        for (int i = 10; i < 15; i++) {
            assertEquals(0, vector.getAccessor().get(i));
        }
        for (int i = 0; i < 20; i++) {
            vector.getMutator().set(i, 0xdeadbeef);
        }
        writer.postRollover();
        index.index = 0;
        writer.saveRow();
        for (int i = 1; i < 5; i++) {
            index.index = i;
            writer.startRow();
            writer.saveRow();
        }
        for (int i = 5; i < 10; i++) {
            index.index = i;
            writer.startRow();
            writer.setInt(i + 20);
            writer.saveRow();
        }
        writer.endWrite();
        for (int i = 0; i < 5; i++) {
            assertEquals(0, vector.getAccessor().get(i));
        }
        for (int i = 5; i < 10; i++) {
            assertEquals(i + 20, vector.getAccessor().get(i));
        }
    }
}
Also used : IntVector(org.apache.drill.exec.vector.IntVector) IntColumnWriter(org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 62 with IntVector

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

the class TestFixedWidthWriter method testSkipNulls.

/**
 * Test the case in which a scalar vector is used in conjunction
 * with a nullable bits vector. The nullable vector will call the
 * <tt>skipNulls()</tt> method to avoid writing values for null
 * entries. (Without the call, the scalar writer will fill the
 * empty values with zeros.)
 */
@Test
public void testSkipNulls() {
    try (IntVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        IntColumnWriter writer = makeWriter(vector, index);
        writer.startWrite();
        // Write values, skipping four out of five positions,
        // skipping nulls.
        // The loop will cause the vector to double in size.
        // The number of values is odd, forcing the writer to
        // skip nulls at the end as well as between values.
        long origAddr = vector.getBuffer().addr();
        for (int i = 0; i < 3000; i += 5) {
            index.index = i;
            writer.startRow();
            writer.skipNulls();
            writer.setInt(i);
            writer.saveRow();
        }
        index.index = 3003;
        writer.startRow();
        writer.skipNulls();
        writer.saveRow();
        writer.endWrite();
        // Should have been reallocated.
        assertNotEquals(origAddr, vector.getBuffer().addr());
        for (int i = 0; i < 1000; i++) {
            assertEquals("Mismatch at " + i, (i % 5) == 0 ? i : 0xdeadbeef, vector.getAccessor().get(i));
        }
        for (int i = 1005; i < 3000; i += 5) {
            assertEquals(i, vector.getAccessor().get(i));
        }
    }
}
Also used : IntVector(org.apache.drill.exec.vector.IntVector) IntColumnWriter(org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 63 with IntVector

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

the class TestResultVectorCache method testClose.

@Test
public void testClose() {
    final ResultVectorCache cache = new ResultVectorCacheImpl(fixture.allocator());
    // Create a vector
    final MaterializedField required = MaterializedField.create("a", MajorType.newBuilder().setMinorType(MinorType.INT).setMode(DataMode.REQUIRED).build());
    final IntVector vector1 = (IntVector) cache.vectorFor(required);
    vector1.allocateNew(100);
    // Close the cache. Note: close is on the implementation, not
    // the interface, because only the implementation should decide
    // when to close.
    // Close should release the allocated vector. If not, then
    // this test suite will fail with a memory leak when shutting
    // down the root allocator.
    ((ResultVectorCacheImpl) cache).close();
    assertEquals(0, vector1.getBuffer().capacity());
}
Also used : ResultVectorCache(org.apache.drill.exec.physical.resultSet.ResultVectorCache) IntVector(org.apache.drill.exec.vector.IntVector) MaterializedField(org.apache.drill.exec.record.MaterializedField) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 64 with IntVector

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

the class TestFixedWidthWriter method testSizeLimit.

/**
 * Test resize monitoring. Add a listener to an int writer,
 * capture each resize, and refuse a resize when the number
 * of ints exceeds 8K values. This will trigger an overflow,
 * which will throw an exception which we then check for.
 */
@Test
public void testSizeLimit() {
    try (IntVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        IntColumnWriter writer = makeWriter(vector, index);
        writer.bindListener(new ColumnWriterListener() {

            int totalAlloc = 4096;

            @Override
            public void overflowed(ScalarWriter writer) {
                throw new IllegalStateException("overflow called");
            }

            @Override
            public boolean canExpand(ScalarWriter writer, int delta) {
                totalAlloc += delta;
                return totalAlloc < 16_384 * 4;
            }
        });
        writer.startWrite();
        try {
            for (int i = 0; ; i++) {
                index.index = i;
                writer.startRow();
                writer.setInt(i);
                writer.saveRow();
            }
        } catch (IllegalStateException e) {
            assertTrue(e.getMessage().contains("overflow called"));
        }
        // Should have failed on 8192, which doubled vector
        // to 16K, which was rejected.
        assertEquals(8192, index.index);
    }
}
Also used : ColumnWriterListener(org.apache.drill.exec.vector.accessor.writer.WriterEvents.ColumnWriterListener) IntVector(org.apache.drill.exec.vector.IntVector) IntColumnWriter(org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 65 with IntVector

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

the class TestFixedWidthWriter method testRestartRow.

@Test
public void testRestartRow() {
    try (IntVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        IntColumnWriter writer = makeWriter(vector, index);
        writer.startWrite();
        // Write rows, rewriting every other row.
        writer.startRow();
        index.index = 0;
        for (int i = 0; i < 50; i++) {
            writer.setInt(i);
            if (i % 2 == 0) {
                writer.saveRow();
                writer.startRow();
                index.index++;
            } else {
                writer.restartRow();
            }
        }
        writer.endWrite();
        for (int i = 0; i < 25; i++) {
            assertEquals(2 * i, vector.getAccessor().get(i));
        }
    }
}
Also used : IntVector(org.apache.drill.exec.vector.IntVector) IntColumnWriter(org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

IntVector (org.apache.drill.exec.vector.IntVector)69 Test (org.junit.Test)56 BigIntVector (org.apache.drill.exec.vector.BigIntVector)26 SchemaPath (org.apache.drill.common.expression.SchemaPath)23 ExecTest (org.apache.drill.exec.ExecTest)22 SubOperatorTest (org.apache.drill.test.SubOperatorTest)21 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)18 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)18 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)18 SimpleRootExec (org.apache.drill.exec.physical.impl.SimpleRootExec)18 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)18 OperatorTest (org.apache.drill.categories.OperatorTest)14 IntColumnWriter (org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter)14 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)13 FragmentContextImpl (org.apache.drill.exec.ops.FragmentContextImpl)12 UserClientConnection (org.apache.drill.exec.rpc.UserClientConnection)12 BigIntHolder (org.apache.drill.exec.expr.holders.BigIntHolder)6 IntHolder (org.apache.drill.exec.expr.holders.IntHolder)6 FragmentContext (org.apache.drill.exec.ops.FragmentContext)6 MaterializedField (org.apache.drill.exec.record.MaterializedField)6