Search in sources :

Example 1 with ColumnWriterListener

use of org.apache.drill.exec.vector.accessor.ScalarWriter.ColumnWriterListener in project drill by axbaretto.

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) {
                // System.out.println("Delta: " + 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.ScalarWriter.ColumnWriterListener) 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) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 2 with ColumnWriterListener

use of org.apache.drill.exec.vector.accessor.ScalarWriter.ColumnWriterListener in project drill by axbaretto.

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();
        OffsetVectorWriter 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) {
                // System.out.println("Delta: " + 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 : OffsetVectorWriter(org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriter) ColumnWriterListener(org.apache.drill.exec.vector.accessor.ScalarWriter.ColumnWriterListener) TestIndex(org.apache.drill.test.rowSet.test.TestFixedWidthWriter.TestIndex) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 3 with ColumnWriterListener

use of org.apache.drill.exec.vector.accessor.ScalarWriter.ColumnWriterListener in project drill by axbaretto.

the class TestFixedWidthWriter method testSizeLimit.

/**
 * Test resize monitoring. Add a listener to an int 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 (IntVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        IntColumnWriter 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) {
                // System.out.println("Delta: " + delta);
                totalAlloc += delta;
                return totalAlloc < 16_384 * 4;
            }
        });
        writer.startWrite();
        try {
            for (int i = 0; ; i++) {
                index.index = i;
                writer.startRow();
                writer.setInt(i);
                writer.saveRow();
            }
        } catch (IllegalStateException e) {
            assertTrue(e.getMessage().contains("overflow called"));
        }
        // Should have failed on 8192, which doubled vector
        // to 16K, which was rejected.
        assertEquals(8192, index.index);
    }
}
Also used : ColumnWriterListener(org.apache.drill.exec.vector.accessor.ScalarWriter.ColumnWriterListener) IntVector(org.apache.drill.exec.vector.IntVector) IntColumnWriter(org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter) ScalarWriter(org.apache.drill.exec.vector.accessor.ScalarWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)3 ColumnWriterListener (org.apache.drill.exec.vector.accessor.ScalarWriter.ColumnWriterListener)3 SubOperatorTest (org.apache.drill.test.SubOperatorTest)3 Test (org.junit.Test)3 TestIndex (org.apache.drill.test.rowSet.test.TestFixedWidthWriter.TestIndex)2 IntVector (org.apache.drill.exec.vector.IntVector)1 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)1 VarCharVector (org.apache.drill.exec.vector.VarCharVector)1 IntColumnWriter (org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter)1 VarCharColumnWriter (org.apache.drill.exec.vector.accessor.ColumnAccessors.VarCharColumnWriter)1 OffsetVectorWriter (org.apache.drill.exec.vector.accessor.writer.OffsetVectorWriter)1