Search in sources :

Example 11 with IntColumnWriter

use of org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter in project drill by axbaretto.

the class TestFixedWidthWriter 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 (IntVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        IntColumnWriter writer = makeWriter(vector, index);
        writer.startWrite();
        // Write integers.
        // Write enough that the vector is resized.
        long origAddr = vector.getBuffer().addr();
        for (int i = 0; i < 3000; i++) {
            index.index = i;
            writer.setInt(i * 10);
        }
        writer.endWrite();
        // Should have been reallocated.
        assertNotEquals(origAddr, vector.getBuffer().addr());
        for (int i = 0; i < 3000; i++) {
            assertEquals(i * 10, vector.getAccessor().get(i));
        }
    }
}
Also used : IntVector(org.apache.drill.exec.vector.IntVector) IntColumnWriter(org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 12 with IntColumnWriter

use of org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter in project drill by apache.

the class TestFixedWidthWriter 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 (IntVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        IntColumnWriter writer = makeWriter(vector, index);
        writer.startWrite();
        for (int i = 0; i < 10; i++) {
            index.index = i;
            writer.startRow();
            writer.setInt(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(i, vector.getAccessor().get(i));
        }
        for (int i = 10; i < 15; i++) {
            assertEquals(0, vector.getAccessor().get(i));
        }
        for (int i = 0; i < 20; i++) {
            vector.getMutator().set(i, 0xdeadbeef);
        }
        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.setInt(i + 20);
            writer.saveRow();
        }
        writer.endWrite();
        for (int i = 0; i < 5; i++) {
            assertEquals(0, vector.getAccessor().get(i));
        }
        for (int i = 5; i < 10; i++) {
            assertEquals(i + 20, vector.getAccessor().get(i));
        }
    }
}
Also used : IntVector(org.apache.drill.exec.vector.IntVector) IntColumnWriter(org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 13 with IntColumnWriter

use of org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter in project drill by apache.

the class TestFixedWidthWriter method testSkipNulls.

/**
 * Test the case in which a scalar vector is used in conjunction
 * with a nullable bits vector. The nullable vector will call the
 * <tt>skipNulls()</tt> method to avoid writing values for null
 * entries. (Without the call, the scalar writer will fill the
 * empty values with zeros.)
 */
@Test
public void testSkipNulls() {
    try (IntVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        IntColumnWriter writer = makeWriter(vector, index);
        writer.startWrite();
        // Write values, skipping four out of five positions,
        // skipping nulls.
        // The loop will cause the vector to double in size.
        // The number of values is odd, forcing the writer to
        // skip nulls at the end as well as between values.
        long origAddr = vector.getBuffer().addr();
        for (int i = 0; i < 3000; i += 5) {
            index.index = i;
            writer.startRow();
            writer.skipNulls();
            writer.setInt(i);
            writer.saveRow();
        }
        index.index = 3003;
        writer.startRow();
        writer.skipNulls();
        writer.saveRow();
        writer.endWrite();
        // Should have been reallocated.
        assertNotEquals(origAddr, vector.getBuffer().addr());
        for (int i = 0; i < 1000; i++) {
            assertEquals("Mismatch at " + i, (i % 5) == 0 ? i : 0xdeadbeef, vector.getAccessor().get(i));
        }
        for (int i = 1005; i < 3000; i += 5) {
            assertEquals(i, vector.getAccessor().get(i));
        }
    }
}
Also used : IntVector(org.apache.drill.exec.vector.IntVector) IntColumnWriter(org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 14 with IntColumnWriter

use of org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter in project drill by apache.

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) {
                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.writer.WriterEvents.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)

Example 15 with IntColumnWriter

use of org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter in project drill by apache.

the class TestFixedWidthWriter method testRestartRow.

@Test
public void testRestartRow() {
    try (IntVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        IntColumnWriter writer = makeWriter(vector, index);
        writer.startWrite();
        // Write rows, rewriting every other row.
        writer.startRow();
        index.index = 0;
        for (int i = 0; i < 50; i++) {
            writer.setInt(i);
            if (i % 2 == 0) {
                writer.saveRow();
                writer.startRow();
                index.index++;
            } else {
                writer.restartRow();
            }
        }
        writer.endWrite();
        for (int i = 0; i < 25; i++) {
            assertEquals(2 * i, vector.getAccessor().get(i));
        }
    }
}
Also used : IntVector(org.apache.drill.exec.vector.IntVector) IntColumnWriter(org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

IntColumnWriter (org.apache.drill.exec.vector.accessor.ColumnAccessors.IntColumnWriter)16 IntVector (org.apache.drill.exec.vector.IntVector)14 SubOperatorTest (org.apache.drill.test.SubOperatorTest)14 Test (org.junit.Test)14 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)2 ColumnWriterListener (org.apache.drill.exec.vector.accessor.ScalarWriter.ColumnWriterListener)1 ColumnWriterListener (org.apache.drill.exec.vector.accessor.writer.WriterEvents.ColumnWriterListener)1