Search in sources :

Example 6 with VarCharColumnWriter

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

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

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

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.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 8 with VarCharColumnWriter

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

the class TestVariableWidthWriter 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. For variable-width, there is no difference between
 * filling empties and skipping nulls: both result in zero-sized
 * entries.
 */
@Test
public void testSkipNulls() {
    try (VarCharVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        VarCharColumnWriter writer = makeWriter(vector, index);
        writer.startWrite();
        // Write values, skipping four out of five positions,
        // skipping nulls.
        // The number of values is odd, forcing the writer to
        // skip nulls at the end as well as between values.
        String base = "sample-value";
        for (int i = 0; i < 3000; i += 5) {
            index.index = i;
            writer.startRow();
            writer.skipNulls();
            writer.setString(base + i);
            writer.saveRow();
        }
        index.index = 3003;
        writer.startRow();
        writer.skipNulls();
        writer.saveRow();
        writer.endWrite();
        for (int i = 0; i < 3000; i++) {
            assertEquals("Mismatch at " + i, (i % 5) == 0 ? 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 9 with VarCharColumnWriter

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

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

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

the class TestVariableWidthWriter 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. For variable-width, there is no difference between
 * filling empties and skipping nulls: both result in zero-sized
 * entries.
 */
@Test
public void testSkipNulls() {
    try (VarCharVector vector = allocVector(1000)) {
        TestIndex index = new TestIndex();
        VarCharColumnWriter writer = makeWriter(vector, index);
        writer.startWrite();
        // Write values, skipping four out of five positions,
        // skipping nulls.
        // The number of values is odd, forcing the writer to
        // skip nulls at the end as well as between values.
        String base = "sample-value";
        for (int i = 0; i < 3000; i += 5) {
            index.index = i;
            writer.startRow();
            writer.skipNulls();
            writer.setString(base + i);
            writer.saveRow();
        }
        index.index = 3003;
        writer.startRow();
        writer.skipNulls();
        writer.saveRow();
        writer.endWrite();
        for (int i = 0; i < 3000; i++) {
            assertEquals("Mismatch at " + 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)

Aggregations

VarCharColumnWriter (org.apache.drill.exec.vector.accessor.ColumnAccessors.VarCharColumnWriter)16 VarCharVector (org.apache.drill.exec.vector.VarCharVector)14 SubOperatorTest (org.apache.drill.test.SubOperatorTest)14 Test (org.junit.Test)14 TestIndex (org.apache.drill.exec.physical.rowSet.TestFixedWidthWriter.TestIndex)7 TestIndex (org.apache.drill.test.rowSet.test.TestFixedWidthWriter.TestIndex)7 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