Search in sources :

Example 6 with OffsetVectorWriterImpl

use of org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriterImpl 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 7 with OffsetVectorWriterImpl

use of org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriterImpl 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

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