Search in sources :

Example 1 with TestIndex

use of org.apache.drill.exec.physical.rowSet.TestFixedWidthWriter.TestIndex in project drill by apache.

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();
        OffsetVectorWriterImpl 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.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 : ColumnWriterListener(org.apache.drill.exec.vector.accessor.writer.WriterEvents.ColumnWriterListener) TestIndex(org.apache.drill.exec.physical.rowSet.TestFixedWidthWriter.TestIndex) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) OffsetVectorWriterImpl(org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriterImpl) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 2 with TestIndex

use of org.apache.drill.exec.physical.rowSet.TestFixedWidthWriter.TestIndex in project drill by apache.

the class TestOffsetVectorWriter method testRestartRow.

@Test
public void testRestartRow() {
    try (UInt4Vector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        OffsetVectorWriterImpl 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 : TestIndex(org.apache.drill.exec.physical.rowSet.TestFixedWidthWriter.TestIndex) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) OffsetVectorWriterImpl(org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriterImpl) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 3 with TestIndex

use of org.apache.drill.exec.physical.rowSet.TestFixedWidthWriter.TestIndex in project drill by apache.

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();
        OffsetVectorWriterImpl 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 : TestIndex(org.apache.drill.exec.physical.rowSet.TestFixedWidthWriter.TestIndex) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) OffsetVectorWriterImpl(org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriterImpl) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 4 with TestIndex

use of org.apache.drill.exec.physical.rowSet.TestFixedWidthWriter.TestIndex in project drill by apache.

the class TestVariableWidthWriter method testWrite.

/**
 * Basic test to write a contiguous set of values, enough to cause
 * the vector to double in size twice, then read back the values.
 */
@Test
public void testWrite() {
    try (VarCharVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        VarCharColumnWriter writer = makeWriter(vector, index);
        writer.startWrite();
        // Write integers.
        // Write enough that the vector is resized.
        long origAddr = vector.getBuffer().addr();
        String base = "sample-value";
        for (int i = 0; i < 3000; i++) {
            index.index = i;
            writer.setString(base + i);
        }
        writer.endWrite();
        // Should have been reallocated.
        assertNotEquals(origAddr, vector.getBuffer().addr());
        for (int i = 0; i < 3000; i++) {
            assertEquals(base + i, stringAt(vector, i));
        }
    }
}
Also used : TestIndex(org.apache.drill.exec.physical.rowSet.TestFixedWidthWriter.TestIndex) VarCharColumnWriter(org.apache.drill.exec.vector.accessor.ColumnAccessors.VarCharColumnWriter) VarCharVector(org.apache.drill.exec.vector.VarCharVector) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 5 with TestIndex

use of org.apache.drill.exec.physical.rowSet.TestFixedWidthWriter.TestIndex in project drill by apache.

the class TestVariableWidthWriter 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. For variable-width, there is no difference between
 * filling empties and skipping nulls: both result in zero-sized
 * entries.
 */
@Test
public void testSkipNulls() {
    try (VarCharVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        VarCharColumnWriter writer = makeWriter(vector, index);
        writer.startWrite();
        // Write values, skipping four out of five positions,
        // skipping nulls.
        // The number of values is odd, forcing the writer to
        // skip nulls at the end as well as between values.
        String base = "sample-value";
        for (int i = 0; i < 3000; i += 5) {
            index.index = i;
            writer.startRow();
            writer.skipNulls();
            writer.setString(base + i);
            writer.saveRow();
        }
        index.index = 3003;
        writer.startRow();
        writer.skipNulls();
        writer.saveRow();
        writer.endWrite();
        for (int i = 0; i < 3000; i++) {
            assertEquals("Mismatch at " + i, (i % 5) == 0 ? base + i : "", stringAt(vector, i));
        }
    }
}
Also used : TestIndex(org.apache.drill.exec.physical.rowSet.TestFixedWidthWriter.TestIndex) VarCharColumnWriter(org.apache.drill.exec.vector.accessor.ColumnAccessors.VarCharColumnWriter) VarCharVector(org.apache.drill.exec.vector.VarCharVector) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

TestIndex (org.apache.drill.exec.physical.rowSet.TestFixedWidthWriter.TestIndex)13 SubOperatorTest (org.apache.drill.test.SubOperatorTest)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 OffsetVectorWriterImpl (org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriterImpl)6 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)2 ColumnWriterListener (org.apache.drill.exec.vector.accessor.writer.WriterEvents.ColumnWriterListener)2