Search in sources :

Example 6 with OffsetVectorWriter

use of org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriter in project drill by axbaretto.

the class TestOffsetVectorWriter method testFillEmpties.

/**
 * Offset vectors have specific behavior when back-filling missing values:
 * the last offset must be carried forward into the missing slots. The
 * slots cannot be zero-filled, or entries will end up with a negative
 * length.
 */
@Test
public void testFillEmpties() {
    try (UInt4Vector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        OffsetVectorWriter writer = makeWriter(vector, index);
        writer.startWrite();
        // Pretend to write offsets for values of width 10, but
        // skip four out of five values, forcing backfill.
        // The loop will cause the vector to double in size.
        // The number of values is odd, forcing the writer to
        // back-fill at the end as well as between values.
        long origAddr = vector.getBuffer().addr();
        for (int i = 5; i < 3001; i += 5) {
            index.index = i;
            writer.startRow();
            int startOffset = writer.nextOffset();
            assertEquals((i / 5 - 1) * 10, startOffset);
            writer.setNextOffset(startOffset + 10);
            writer.saveRow();
        }
        index.index = 3003;
        writer.endWrite();
        // Should have been reallocated.
        assertNotEquals(origAddr, vector.getBuffer().addr());
        for (int i = 0; i < 3004; i++) {
            assertEquals(((i - 1) / 5) * 10, vector.getAccessor().get(i));
        }
    }
}
Also used : OffsetVectorWriter(org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriter) TestIndex(org.apache.drill.test.rowSet.test.TestFixedWidthWriter.TestIndex) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 7 with OffsetVectorWriter

use of org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriter in project drill by axbaretto.

the class TestOffsetVectorWriter method testSizeLimit.

/**
 * Test resize monitoring. Add a listener to an offsets 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 (UInt4Vector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        OffsetVectorWriter 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) {
                // System.out.println("Delta: " + delta);
                totalAlloc += delta;
                return totalAlloc < 16_384 * 4;
            }
        });
        writer.startWrite();
        try {
            for (int i = 0; ; i++) {
                index.index = i;
                writer.startRow();
                writer.setNextOffset(i);
                writer.saveRow();
            }
        } catch (IllegalStateException e) {
            assertTrue(e.getMessage().contains("overflow called"));
        }
        // Should have failed on 8191, which doubled vector
        // to 16K, which was rejected. Note the 8191 value,
        // because offsets are one ahead of the index.
        assertEquals(8191, index.index);
    }
}
Also used : OffsetVectorWriter(org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriter) ColumnWriterListener(org.apache.drill.exec.vector.accessor.ScalarWriter.ColumnWriterListener) TestIndex(org.apache.drill.test.rowSet.test.TestFixedWidthWriter.TestIndex) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

OffsetVectorWriter (org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriter)7 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)6 SubOperatorTest (org.apache.drill.test.SubOperatorTest)6 TestIndex (org.apache.drill.test.rowSet.test.TestFixedWidthWriter.TestIndex)6 Test (org.junit.Test)6 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)1 ColumnWriterListener (org.apache.drill.exec.vector.accessor.ScalarWriter.ColumnWriterListener)1