Search in sources :

Example 1 with TestIndex

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

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();
        OffsetVectorWriter 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 : 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 2 with TestIndex

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

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();
        OffsetVectorWriter 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 : 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 3 with TestIndex

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

the class TestVariableWidthWriter method testRestartRow.

@Test
public void testRestartRow() {
    try (VarCharVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        VarCharColumnWriter writer = makeWriter(vector, index);
        writer.startWrite();
        // Write rows, rewriting every other row.
        String base = "sample-value";
        writer.startRow();
        index.index = 0;
        for (int i = 0; i < 50; i++) {
            writer.setString(base + i);
            if (i % 2 == 0) {
                writer.saveRow();
                writer.startRow();
                index.index++;
            } else {
                writer.restartRow();
            }
        }
        writer.endWrite();
        for (int i = 0; i < 25; i++) {
            assertEquals(base + (2 * i), stringAt(vector, i));
        }
    }
}
Also used : TestIndex(org.apache.drill.test.rowSet.test.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 4 with TestIndex

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

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.test.rowSet.test.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.test.rowSet.test.TestFixedWidthWriter.TestIndex in project drill by axbaretto.

the class TestVariableWidthWriter method testRollover.

/**
 * The rollover method is used during vector overflow.
 */
@Test
public void testRollover() {
    try (VarCharVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        VarCharColumnWriter writer = makeWriter(vector, index);
        writer.startWrite();
        // Simulate doing an overflow of ten values.
        String base = "sample-value";
        for (int i = 0; i < 10; i++) {
            index.index = i;
            writer.startRow();
            writer.setString(base + i);
            writer.saveRow();
        }
        // Overflow occurs after writing the 11th row
        index.index = 10;
        writer.startRow();
        String overflowValue = base + 10;
        writer.setString(overflowValue);
        // Overflow occurs
        writer.preRollover();
        // Simulate rollover
        byte[] dummy = new byte[] { (byte) 0x55 };
        for (int i = 0; i < 500; i++) {
            vector.getMutator().setSafe(i, dummy);
        }
        for (int i = 1; i < 15; i++) {
            vector.getOffsetVector().getMutator().set(i, 0xdeadbeef);
        }
        vector.getMutator().setSafe(0, overflowValue.getBytes(Charsets.UTF_8));
        writer.postRollover();
        index.index = 0;
        writer.saveRow();
        for (int i = 1; i < 5; i++) {
            index.index = i;
            writer.startRow();
            writer.setString(base + (i + 10));
            writer.saveRow();
        }
        writer.endWrite();
        for (int i = 0; i < 5; i++) {
            assertEquals(base + (10 + i), stringAt(vector, i));
        }
    }
}
Also used : TestIndex(org.apache.drill.test.rowSet.test.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

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