Search in sources :

Example 11 with TestIndex

use of org.apache.drill.test.rowSet.test.TestFixedWidthWriter.TestIndex in project drill by axbaretto.

the class TestOffsetVectorWriter method testRestartRow.

@Test
public void testRestartRow() {
    try (UInt4Vector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        OffsetVectorWriter writer = makeWriter(vector, index);
        writer.startWrite();
        // Write rows, rewriting every other row.
        writer.startRow();
        index.index = 0;
        for (int i = 0; i < 50; i++) {
            if (i % 2 == 0) {
                assertEquals(i == 0 ? 0 : (i - 1) * 10, writer.nextOffset());
                writer.setNextOffset((i + 1) * 10);
                writer.saveRow();
                writer.startRow();
                index.index++;
            } else {
                writer.setNextOffset((i + 1) * 10);
                writer.restartRow();
            }
        }
        writer.endWrite();
        // Verify values
        assertEquals(0, vector.getAccessor().get(0));
        for (int i = 1; i < 25; i++) {
            assertEquals((2 * i - 1) * 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 12 with TestIndex

use of org.apache.drill.test.rowSet.test.TestFixedWidthWriter.TestIndex 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 13 with TestIndex

use of org.apache.drill.test.rowSet.test.TestFixedWidthWriter.TestIndex 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

SubOperatorTest (org.apache.drill.test.SubOperatorTest)13 TestIndex (org.apache.drill.test.rowSet.test.TestFixedWidthWriter.TestIndex)13 Test (org.junit.Test)13 VarCharVector (org.apache.drill.exec.vector.VarCharVector)7 VarCharColumnWriter (org.apache.drill.exec.vector.accessor.ColumnAccessors.VarCharColumnWriter)7 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)6 OffsetVectorWriter (org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriter)6 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)2 ColumnWriterListener (org.apache.drill.exec.vector.accessor.ScalarWriter.ColumnWriterListener)2