Search in sources :

Example 11 with BooleanStreamCheckpoint

use of com.facebook.presto.orc.checkpoint.BooleanStreamCheckpoint in project presto by prestodb.

the class DictionaryColumnWriter method getIndexStreams.

@Override
public List<StreamDataOutput> getIndexStreams() throws IOException {
    checkState(closed);
    if (directEncoded) {
        return getDirectColumnWriter().getIndexStreams();
    }
    ImmutableList.Builder<RowGroupIndex> rowGroupIndexes = ImmutableList.builder();
    List<LongStreamCheckpoint> dataCheckpoints = dataStream.getCheckpoints();
    Optional<List<BooleanStreamCheckpoint>> presentCheckpoints = presentStream.getCheckpoints();
    for (int i = 0; i < rowGroups.size(); i++) {
        int groupId = i;
        ColumnStatistics columnStatistics = rowGroups.get(groupId).getColumnStatistics();
        LongStreamCheckpoint dataCheckpoint = dataCheckpoints.get(groupId);
        Optional<BooleanStreamCheckpoint> presentCheckpoint = presentCheckpoints.map(checkpoints -> checkpoints.get(groupId));
        List<Integer> positions = createSliceColumnPositionList(columnWriterOptions.getCompressionKind() != NONE, dataCheckpoint, presentCheckpoint);
        rowGroupIndexes.add(new RowGroupIndex(positions, columnStatistics));
    }
    Slice slice = compressedMetadataWriter.writeRowIndexes(rowGroupIndexes.build());
    Stream stream = new Stream(column, StreamKind.ROW_INDEX, slice.length(), false);
    return ImmutableList.of(new StreamDataOutput(slice, stream));
}
Also used : ColumnStatistics(com.facebook.presto.orc.metadata.statistics.ColumnStatistics) BooleanStreamCheckpoint(com.facebook.presto.orc.checkpoint.BooleanStreamCheckpoint) ImmutableList(com.google.common.collect.ImmutableList) StreamDataOutput(com.facebook.presto.orc.stream.StreamDataOutput) LongStreamCheckpoint(com.facebook.presto.orc.checkpoint.LongStreamCheckpoint) LongStreamCheckpoint(com.facebook.presto.orc.checkpoint.LongStreamCheckpoint) BooleanStreamCheckpoint(com.facebook.presto.orc.checkpoint.BooleanStreamCheckpoint) RowGroupIndex(com.facebook.presto.orc.metadata.RowGroupIndex) Slice(io.airlift.slice.Slice) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) PresentOutputStream(com.facebook.presto.orc.stream.PresentOutputStream) LongOutputStream(com.facebook.presto.orc.stream.LongOutputStream) Stream(com.facebook.presto.orc.metadata.Stream) LongOutputStream.createDataOutputStream(com.facebook.presto.orc.stream.LongOutputStream.createDataOutputStream)

Example 12 with BooleanStreamCheckpoint

use of com.facebook.presto.orc.checkpoint.BooleanStreamCheckpoint in project presto by prestodb.

the class DoubleColumnWriter method getIndexStreams.

@Override
public List<StreamDataOutput> getIndexStreams() throws IOException {
    checkState(closed);
    ImmutableList.Builder<RowGroupIndex> rowGroupIndexes = ImmutableList.builder();
    List<DoubleStreamCheckpoint> dataCheckpoints = dataStream.getCheckpoints();
    Optional<List<BooleanStreamCheckpoint>> presentCheckpoints = presentStream.getCheckpoints();
    for (int i = 0; i < rowGroupColumnStatistics.size(); i++) {
        int groupId = i;
        ColumnStatistics columnStatistics = rowGroupColumnStatistics.get(groupId);
        DoubleStreamCheckpoint dataCheckpoint = dataCheckpoints.get(groupId);
        Optional<BooleanStreamCheckpoint> presentCheckpoint = presentCheckpoints.map(checkpoints -> checkpoints.get(groupId));
        List<Integer> positions = createDoubleColumnPositionList(compressed, dataCheckpoint, presentCheckpoint);
        rowGroupIndexes.add(new RowGroupIndex(positions, columnStatistics));
    }
    Slice slice = metadataWriter.writeRowIndexes(rowGroupIndexes.build());
    Stream stream = new Stream(column, StreamKind.ROW_INDEX, slice.length(), false);
    return ImmutableList.of(new StreamDataOutput(slice, stream));
}
Also used : ColumnStatistics(com.facebook.presto.orc.metadata.statistics.ColumnStatistics) BooleanStreamCheckpoint(com.facebook.presto.orc.checkpoint.BooleanStreamCheckpoint) ImmutableList(com.google.common.collect.ImmutableList) StreamDataOutput(com.facebook.presto.orc.stream.StreamDataOutput) DoubleStreamCheckpoint(com.facebook.presto.orc.checkpoint.DoubleStreamCheckpoint) BooleanStreamCheckpoint(com.facebook.presto.orc.checkpoint.BooleanStreamCheckpoint) RowGroupIndex(com.facebook.presto.orc.metadata.RowGroupIndex) Slice(io.airlift.slice.Slice) DoubleStreamCheckpoint(com.facebook.presto.orc.checkpoint.DoubleStreamCheckpoint) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) PresentOutputStream(com.facebook.presto.orc.stream.PresentOutputStream) Stream(com.facebook.presto.orc.metadata.Stream) DoubleOutputStream(com.facebook.presto.orc.stream.DoubleOutputStream)

Example 13 with BooleanStreamCheckpoint

use of com.facebook.presto.orc.checkpoint.BooleanStreamCheckpoint in project presto by prestodb.

the class BooleanColumnWriter method getIndexStreams.

@Override
public List<StreamDataOutput> getIndexStreams() throws IOException {
    checkState(closed);
    ImmutableList.Builder<RowGroupIndex> rowGroupIndexes = ImmutableList.builder();
    List<BooleanStreamCheckpoint> dataCheckpoints = dataStream.getCheckpoints();
    Optional<List<BooleanStreamCheckpoint>> presentCheckpoints = presentStream.getCheckpoints();
    for (int i = 0; i < rowGroupColumnStatistics.size(); i++) {
        int groupId = i;
        ColumnStatistics columnStatistics = rowGroupColumnStatistics.get(groupId);
        BooleanStreamCheckpoint dataCheckpoint = dataCheckpoints.get(groupId);
        Optional<BooleanStreamCheckpoint> presentCheckpoint = presentCheckpoints.map(checkpoints -> checkpoints.get(groupId));
        List<Integer> positions = createBooleanColumnPositionList(compressed, dataCheckpoint, presentCheckpoint);
        rowGroupIndexes.add(new RowGroupIndex(positions, columnStatistics));
    }
    Slice slice = metadataWriter.writeRowIndexes(rowGroupIndexes.build());
    Stream stream = new Stream(column, StreamKind.ROW_INDEX, slice.length(), false);
    return ImmutableList.of(new StreamDataOutput(slice, stream));
}
Also used : ColumnStatistics(com.facebook.presto.orc.metadata.statistics.ColumnStatistics) BooleanStreamCheckpoint(com.facebook.presto.orc.checkpoint.BooleanStreamCheckpoint) ImmutableList(com.google.common.collect.ImmutableList) StreamDataOutput(com.facebook.presto.orc.stream.StreamDataOutput) BooleanStreamCheckpoint(com.facebook.presto.orc.checkpoint.BooleanStreamCheckpoint) RowGroupIndex(com.facebook.presto.orc.metadata.RowGroupIndex) Slice(io.airlift.slice.Slice) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) PresentOutputStream(com.facebook.presto.orc.stream.PresentOutputStream) BooleanOutputStream(com.facebook.presto.orc.stream.BooleanOutputStream) Stream(com.facebook.presto.orc.metadata.Stream)

Example 14 with BooleanStreamCheckpoint

use of com.facebook.presto.orc.checkpoint.BooleanStreamCheckpoint in project presto by prestodb.

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));
    DataSize compressionSize = new DataSize(1, KILOBYTE);
    for (List<Integer> counts : testGroups) {
        ColumnWriterOptions columnWriterOptions = ColumnWriterOptions.builder().setCompressionKind(NONE).setCompressionMaxBufferSize(compressionSize).build();
        OrcOutputBuffer buffer = new OrcOutputBuffer(columnWriterOptions, Optional.empty());
        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 : BooleanStreamCheckpoint(com.facebook.presto.orc.checkpoint.BooleanStreamCheckpoint) BooleanStreamCheckpoint(com.facebook.presto.orc.checkpoint.BooleanStreamCheckpoint) ByteStreamCheckpoint(com.facebook.presto.orc.checkpoint.ByteStreamCheckpoint) OrcOutputBuffer(com.facebook.presto.orc.OrcOutputBuffer) ColumnWriterOptions(com.facebook.presto.orc.ColumnWriterOptions) Slice(io.airlift.slice.Slice) DataSize(io.airlift.units.DataSize) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.testng.annotations.Test)

Aggregations

BooleanStreamCheckpoint (com.facebook.presto.orc.checkpoint.BooleanStreamCheckpoint)14 ImmutableList (com.google.common.collect.ImmutableList)14 Slice (io.airlift.slice.Slice)13 List (java.util.List)13 RowGroupIndex (com.facebook.presto.orc.metadata.RowGroupIndex)12 Stream (com.facebook.presto.orc.metadata.Stream)12 ColumnStatistics (com.facebook.presto.orc.metadata.statistics.ColumnStatistics)12 PresentOutputStream (com.facebook.presto.orc.stream.PresentOutputStream)12 StreamDataOutput (com.facebook.presto.orc.stream.StreamDataOutput)12 ArrayList (java.util.ArrayList)12 LongStreamCheckpoint (com.facebook.presto.orc.checkpoint.LongStreamCheckpoint)7 LongOutputStream (com.facebook.presto.orc.stream.LongOutputStream)7 ByteStreamCheckpoint (com.facebook.presto.orc.checkpoint.ByteStreamCheckpoint)3 LongOutputStream.createLengthOutputStream (com.facebook.presto.orc.stream.LongOutputStream.createLengthOutputStream)3 ColumnWriterOptions (com.facebook.presto.orc.ColumnWriterOptions)1 OrcOutputBuffer (com.facebook.presto.orc.OrcOutputBuffer)1 ByteArrayStreamCheckpoint (com.facebook.presto.orc.checkpoint.ByteArrayStreamCheckpoint)1 DecimalStreamCheckpoint (com.facebook.presto.orc.checkpoint.DecimalStreamCheckpoint)1 DoubleStreamCheckpoint (com.facebook.presto.orc.checkpoint.DoubleStreamCheckpoint)1 FloatStreamCheckpoint (com.facebook.presto.orc.checkpoint.FloatStreamCheckpoint)1