Search in sources :

Example 6 with TestIndex

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

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.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 7 with TestIndex

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

the class TestVariableWidthWriter method testSizeLimit.

/**
 * Test resize monitoring. Add a listener to an Varchar writer,
 * capture each resize, and refuse a resize when the s
 * of the vector exceeds 1 MB. This will trigger an overflow,
 * which will throw an exception which we then check for.
 */
@Test
public void testSizeLimit() {
    try (VarCharVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        VarCharColumnWriter writer = makeWriter(vector, index);
        writer.bindListener(new ColumnWriterListener() {

            // Because assumed array size is 10, so 10 * 1000 = 10,000
            // rounded to 16K
            int totalAlloc = 16384;

            @Override
            public void overflowed(ScalarWriter writer) {
                throw new IllegalStateException("overflow called");
            }

            @Override
            public boolean canExpand(ScalarWriter writer, int delta) {
                totalAlloc += delta;
                return totalAlloc < 1024 * 1024;
            }
        });
        writer.startWrite();
        byte[] value = new byte[423];
        Arrays.fill(value, (byte) 'X');
        try {
            for (int i = 0; ; i++) {
                index.index = i;
                writer.startRow();
                writer.setBytes(value, value.length);
                writer.saveRow();
            }
        } catch (IllegalStateException e) {
            assertTrue(e.getMessage().contains("overflow called"));
        }
    }
}
Also used : ColumnWriterListener(org.apache.drill.exec.vector.accessor.writer.WriterEvents.ColumnWriterListener) 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) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 8 with TestIndex

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

the class TestVariableWidthWriter 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 (VarCharVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        VarCharColumnWriter writer = makeWriter(vector, index);
        writer.startWrite();
        // Simulate doing an overflow of 15 values,
        // of which 5 are empty.
        String base = "sample-value";
        for (int i = 0; i < 10; i++) {
            index.index = i;
            writer.startRow();
            writer.setString(base + i);
            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 < 10; i++) {
            assertEquals(base + i, stringAt(vector, i));
        }
        for (int i = 10; i < 15; i++) {
            assertEquals("", stringAt(vector, i));
        }
        // 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, new byte[] {});
        writer.postRollover();
        index.index = 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.setString(base + (i + 20));
            writer.saveRow();
        }
        writer.endWrite();
        for (int i = 0; i < 5; i++) {
            assertEquals("", stringAt(vector, i));
        }
        for (int i = 5; i < 10; i++) {
            assertEquals(base + (i + 20), 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 9 with TestIndex

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

the class TestVariableWidthWriter method testFillEmpties.

/**
 * Filling empties in a variable-width row means carrying forward
 * offsets (as tested elsewhere), leaving zero-length values.
 */
@Test
public void testFillEmpties() {
    try (VarCharVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        VarCharColumnWriter writer = makeWriter(vector, index);
        writer.startWrite();
        // Write values, skipping four out of five positions,
        // forcing backfill.
        // The number of values is odd, forcing the writer to
        // back-fill at the end as well as between values.
        String base = "sample-value";
        for (int i = 0; i < 501; i += 5) {
            index.index = i;
            writer.startRow();
            writer.setString(base + i);
            writer.saveRow();
        }
        // At end, vector index defined to point one past the
        // last row. That is, the vector index gives the row count.
        index.index = 504;
        writer.endWrite();
        for (int i = 0; i < 504; i++) {
            assertEquals("Mismatch on " + 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)

Example 10 with TestIndex

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

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.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