Search in sources :

Example 1 with OrcOutputBuffer

use of io.prestosql.orc.OrcOutputBuffer in project hetu-core by openlookeng.

the class TestBooleanOutputStream method testWriteBoolean.

@Test
public void testWriteBoolean() {
    List<List<Integer>> testGroups = ImmutableList.of(ImmutableList.of(149, 317, 2), ImmutableList.of(2), ImmutableList.of(1, 2, 4, 0, 8), ImmutableList.of(1, 4, 8, 1024, 10000), ImmutableList.of(14000, 1, 2));
    for (List<Integer> counts : testGroups) {
        OrcOutputBuffer buffer = new OrcOutputBuffer(NONE, 1024);
        BooleanOutputStream output = new BooleanOutputStream(buffer);
        // write multiple booleans together
        for (int count : counts) {
            output.writeBooleans(count, true);
            output.recordCheckpoint();
        }
        output.close();
        List<BooleanStreamCheckpoint> batchWriteCheckpoints = output.getCheckpoints();
        DynamicSliceOutput slice = new DynamicSliceOutput(128);
        buffer.writeDataTo(slice);
        Slice batchWriteBuffer = slice.slice();
        // write one boolean a time
        buffer.reset();
        output.reset();
        for (int count : counts) {
            for (int i = 0; i < count; i++) {
                output.writeBoolean(true);
            }
            output.recordCheckpoint();
        }
        output.close();
        List<BooleanStreamCheckpoint> singleWriteCheckpoints = output.getCheckpoints();
        slice = new DynamicSliceOutput(128);
        buffer.writeDataTo(slice);
        Slice singleWriteBuffer = slice.slice();
        assertEquals(batchWriteCheckpoints.size(), singleWriteCheckpoints.size());
        for (int i = 0; i < batchWriteCheckpoints.size(); i++) {
            assertTrue(checkpointsEqual(batchWriteCheckpoints.get(i), singleWriteCheckpoints.get(i)));
        }
        assertEquals(batchWriteBuffer, singleWriteBuffer);
    }
}
Also used : OrcOutputBuffer(io.prestosql.orc.OrcOutputBuffer) BooleanStreamCheckpoint(io.prestosql.orc.checkpoint.BooleanStreamCheckpoint) Slice(io.airlift.slice.Slice) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) BooleanStreamCheckpoint(io.prestosql.orc.checkpoint.BooleanStreamCheckpoint) ByteStreamCheckpoint(io.prestosql.orc.checkpoint.ByteStreamCheckpoint) Test(org.testng.annotations.Test)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 DynamicSliceOutput (io.airlift.slice.DynamicSliceOutput)1 Slice (io.airlift.slice.Slice)1 OrcOutputBuffer (io.prestosql.orc.OrcOutputBuffer)1 BooleanStreamCheckpoint (io.prestosql.orc.checkpoint.BooleanStreamCheckpoint)1 ByteStreamCheckpoint (io.prestosql.orc.checkpoint.ByteStreamCheckpoint)1 List (java.util.List)1 Test (org.testng.annotations.Test)1