Search in sources :

Example 11 with TestIndex

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

the class TestOffsetVectorWriter 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 (UInt4Vector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        OffsetVectorWriterImpl writer = makeWriter(vector, index);
        writer.startWrite();
        for (int i = 0; i < 10; i++) {
            index.index = i;
            writer.startRow();
            writer.setNextOffset((i + 1) * 10);
            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 < 11; i++) {
            assertEquals("i = " + i, i * 10, vector.getAccessor().get(i));
        }
        for (int i = 11; i < 16; i++) {
            assertEquals("i = " + i, 100, vector.getAccessor().get(i));
        }
        for (int i = 0; i < 20; i++) {
            vector.getMutator().set(i, 0xdeadbeef);
        }
        // Simulate finishing the overflow row.
        index.index++;
        // Post rollover, slot 0 should be initialized.
        // This is a rollover. This row must set the value
        // for the new row 0 (which was presumably set/filled
        // after the overflow.)
        writer.postRollover();
        index.index = 0;
        writer.setNextOffset(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.setNextOffset((i - 4) * 10);
            writer.saveRow();
        }
        writer.endWrite();
        for (int i = 0; i < 6; i++) {
            assertEquals("Index + " + i, 0, vector.getAccessor().get(i));
        }
        for (int i = 6; i < 11; i++) {
            assertEquals("Index + " + i, (i - 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 12 with TestIndex

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

the class TestOffsetVectorWriter method testWrite.

/**
 * Basic test to write a contiguous set of offsets, enough to cause
 * the vector to double in size twice, then read back the values.
 */
@Test
public void testWrite() {
    try (UInt4Vector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        OffsetVectorWriterImpl writer = makeWriter(vector, index);
        // Start write sets initial position to 0.
        writer.startWrite();
        assertEquals(0, vector.getAccessor().get(0));
        // Pretend to write offsets for values of width 10. We write
        // the end position of each field.
        // Write enough that the vector is resized.
        long origAddr = vector.getBuffer().addr();
        for (int i = 0; i < 3000; i++) {
            index.index = i;
            writer.startRow();
            assertEquals(i * 10, writer.nextOffset());
            writer.setNextOffset((i + 1) * 10);
            assertEquals((i + 1) * 10, writer.nextOffset());
            writer.saveRow();
        }
        writer.endWrite();
        // Should have been reallocated.
        assertNotEquals(origAddr, vector.getBuffer().addr());
        for (int i = 0; i < 3001; i++) {
            assertEquals(i * 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 13 with TestIndex

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

the class TestOffsetVectorWriter method testRollover.

/**
 * The rollover method is used during vector overflow.
 */
@Test
public void testRollover() {
    try (UInt4Vector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        OffsetVectorWriterImpl writer = makeWriter(vector, index);
        writer.startWrite();
        for (int i = 0; i < 10; i++) {
            index.index = i;
            writer.startRow();
            writer.setNextOffset((i + 1) * 10);
            writer.saveRow();
        }
        // Overflow occurs after writing the 11th row
        index.index = 10;
        writer.startRow();
        writer.setNextOffset(110);
        // Overflow occurs
        writer.preRollover();
        for (int i = 0; i < 15; i++) {
            vector.getMutator().set(i, 0xdeadbeef);
        }
        // Simulate shifting the last value down (which changes
        // the offset.)
        vector.getMutator().set(1, 10);
        // Post rollover, slot 0 should be initialized
        writer.postRollover();
        index.index = 0;
        writer.saveRow();
        for (int i = 1; i < 5; i++) {
            index.index = i;
            writer.startRow();
            writer.setNextOffset((i + 1) * 10);
            writer.saveRow();
        }
        writer.endWrite();
        for (int i = 0; i < 6; i++) {
            assertEquals(i * 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)

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