Search in sources :

Example 1 with StreamCheckpoint

use of io.trino.orc.checkpoint.StreamCheckpoint in project trino by trinodb.

the class StripeReader method createRowGroups.

private List<RowGroup> createRowGroups(int rowsInStripe, Map<StreamId, Stream> streams, Map<StreamId, ValueInputStream<?>> valueStreams, Map<StreamId, List<RowGroupIndex>> columnIndexes, Set<Integer> selectedRowGroups, ColumnMetadata<ColumnEncoding> encodings) throws InvalidCheckpointException {
    int rowsInRowGroup = this.rowsInRowGroup.orElseThrow(() -> new IllegalStateException("Cannot create row groups if row group info is missing"));
    ImmutableList.Builder<RowGroup> rowGroupBuilder = ImmutableList.builder();
    for (int rowGroupId : selectedRowGroups) {
        Map<StreamId, StreamCheckpoint> checkpoints = getStreamCheckpoints(includedOrcColumnIds, types, decompressor.isPresent(), rowGroupId, encodings, streams, columnIndexes);
        int rowOffset = rowGroupId * rowsInRowGroup;
        int rowsInGroup = Math.min(rowsInStripe - rowOffset, rowsInRowGroup);
        long minAverageRowBytes = columnIndexes.entrySet().stream().mapToLong(e -> e.getValue().get(rowGroupId).getColumnStatistics().getMinAverageValueSizeInBytes()).sum();
        rowGroupBuilder.add(createRowGroup(rowGroupId, rowOffset, rowsInGroup, minAverageRowBytes, valueStreams, checkpoints));
    }
    return rowGroupBuilder.build();
}
Also used : RowGroupIndex(io.trino.orc.metadata.RowGroupIndex) ColumnEncoding(io.trino.orc.metadata.ColumnEncoding) OrcTypeKind(io.trino.orc.metadata.OrcType.OrcTypeKind) DICTIONARY_V2(io.trino.orc.metadata.ColumnEncoding.ColumnEncodingKind.DICTIONARY_V2) Stream(io.trino.orc.metadata.Stream) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Map(java.util.Map) OrcChunkLoader(io.trino.orc.stream.OrcChunkLoader) BLOOM_FILTER(io.trino.orc.metadata.Stream.StreamKind.BLOOM_FILTER) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Checkpoints.getStreamCheckpoints(io.trino.orc.checkpoint.Checkpoints.getStreamCheckpoints) HiveWriterVersion(io.trino.orc.metadata.PostScript.HiveWriterVersion) Collection(java.util.Collection) InvalidCheckpointException(io.trino.orc.checkpoint.InvalidCheckpointException) Set(java.util.Set) ZoneId(java.time.ZoneId) ColumnEncodingKind(io.trino.orc.metadata.ColumnEncoding.ColumnEncodingKind) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Entry(java.util.Map.Entry) Optional(java.util.Optional) ValueInputStreamSource(io.trino.orc.stream.ValueInputStreamSource) ColumnStatistics(io.trino.orc.metadata.statistics.ColumnStatistics) InputStreamSources(io.trino.orc.stream.InputStreamSources) MetadataReader(io.trino.orc.metadata.MetadataReader) Slice(io.airlift.slice.Slice) StreamCheckpoint(io.trino.orc.checkpoint.StreamCheckpoint) HashMap(java.util.HashMap) InputStreamSource(io.trino.orc.stream.InputStreamSource) OptionalInt(java.util.OptionalInt) ArrayList(java.util.ArrayList) OrcDataReader(io.trino.orc.stream.OrcDataReader) ROW_INDEX(io.trino.orc.metadata.Stream.StreamKind.ROW_INDEX) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) Predicates(com.google.common.base.Predicates) AggregatedMemoryContext(io.trino.memory.context.AggregatedMemoryContext) StripeInformation(io.trino.orc.metadata.StripeInformation) Math.toIntExact(java.lang.Math.toIntExact) LinkedHashSet(java.util.LinkedHashSet) StripeFooter(io.trino.orc.metadata.StripeFooter) OrcType(io.trino.orc.metadata.OrcType) Checkpoints.getDictionaryStreamCheckpoint(io.trino.orc.checkpoint.Checkpoints.getDictionaryStreamCheckpoint) ValueStreams(io.trino.orc.stream.ValueStreams) OrcInputStream(io.trino.orc.stream.OrcInputStream) BloomFilter(io.trino.orc.metadata.statistics.BloomFilter) IOException(java.io.IOException) ColumnMetadata(io.trino.orc.metadata.ColumnMetadata) DICTIONARY(io.trino.orc.metadata.ColumnEncoding.ColumnEncodingKind.DICTIONARY) Maps(com.google.common.collect.Maps) BLOOM_FILTER_UTF8(io.trino.orc.metadata.Stream.StreamKind.BLOOM_FILTER_UTF8) ValueInputStream(io.trino.orc.stream.ValueInputStream) DICTIONARY_COUNT(io.trino.orc.metadata.Stream.StreamKind.DICTIONARY_COUNT) LENGTH(io.trino.orc.metadata.Stream.StreamKind.LENGTH) DICTIONARY_DATA(io.trino.orc.metadata.Stream.StreamKind.DICTIONARY_DATA) CheckpointInputStreamSource.createCheckpointStreamSource(io.trino.orc.stream.CheckpointInputStreamSource.createCheckpointStreamSource) OrcColumnId(io.trino.orc.metadata.OrcColumnId) InputStream(java.io.InputStream) ImmutableList(com.google.common.collect.ImmutableList) StreamCheckpoint(io.trino.orc.checkpoint.StreamCheckpoint) Checkpoints.getDictionaryStreamCheckpoint(io.trino.orc.checkpoint.Checkpoints.getDictionaryStreamCheckpoint) StreamCheckpoint(io.trino.orc.checkpoint.StreamCheckpoint) Checkpoints.getDictionaryStreamCheckpoint(io.trino.orc.checkpoint.Checkpoints.getDictionaryStreamCheckpoint)

Example 2 with StreamCheckpoint

use of io.trino.orc.checkpoint.StreamCheckpoint in project trino by trinodb.

the class StripeReader method createDictionaryStreamSources.

private InputStreamSources createDictionaryStreamSources(Map<StreamId, Stream> streams, Map<StreamId, ValueInputStream<?>> valueStreams, ColumnMetadata<ColumnEncoding> columnEncodings) {
    ImmutableMap.Builder<StreamId, InputStreamSource<?>> dictionaryStreamBuilder = ImmutableMap.builder();
    for (Entry<StreamId, Stream> entry : streams.entrySet()) {
        StreamId streamId = entry.getKey();
        Stream stream = entry.getValue();
        OrcColumnId column = stream.getColumnId();
        // only process dictionary streams
        ColumnEncodingKind columnEncoding = columnEncodings.get(column).getColumnEncodingKind();
        if (!isDictionary(stream, columnEncoding)) {
            continue;
        }
        // skip streams without data
        ValueInputStream<?> valueStream = valueStreams.get(streamId);
        if (valueStream == null) {
            continue;
        }
        OrcTypeKind columnType = types.get(stream.getColumnId()).getOrcTypeKind();
        StreamCheckpoint streamCheckpoint = getDictionaryStreamCheckpoint(streamId, columnType, columnEncoding);
        InputStreamSource<?> streamSource = createCheckpointStreamSource(valueStream, streamCheckpoint);
        dictionaryStreamBuilder.put(streamId, streamSource);
    }
    return new InputStreamSources(dictionaryStreamBuilder.buildOrThrow());
}
Also used : OrcColumnId(io.trino.orc.metadata.OrcColumnId) OrcTypeKind(io.trino.orc.metadata.OrcType.OrcTypeKind) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ValueInputStreamSource(io.trino.orc.stream.ValueInputStreamSource) InputStreamSource(io.trino.orc.stream.InputStreamSource) InputStreamSources(io.trino.orc.stream.InputStreamSources) Stream(io.trino.orc.metadata.Stream) OrcInputStream(io.trino.orc.stream.OrcInputStream) ValueInputStream(io.trino.orc.stream.ValueInputStream) InputStream(java.io.InputStream) ColumnEncodingKind(io.trino.orc.metadata.ColumnEncoding.ColumnEncodingKind) StreamCheckpoint(io.trino.orc.checkpoint.StreamCheckpoint) Checkpoints.getDictionaryStreamCheckpoint(io.trino.orc.checkpoint.Checkpoints.getDictionaryStreamCheckpoint)

Example 3 with StreamCheckpoint

use of io.trino.orc.checkpoint.StreamCheckpoint in project trino by trinodb.

the class StripeReader method createRowGroup.

private static RowGroup createRowGroup(int groupId, int rowOffset, int rowCount, long minAverageRowBytes, Map<StreamId, ValueInputStream<?>> valueStreams, Map<StreamId, StreamCheckpoint> checkpoints) {
    ImmutableMap.Builder<StreamId, InputStreamSource<?>> builder = ImmutableMap.builder();
    for (Entry<StreamId, StreamCheckpoint> entry : checkpoints.entrySet()) {
        StreamId streamId = entry.getKey();
        StreamCheckpoint checkpoint = entry.getValue();
        // skip streams without data
        ValueInputStream<?> valueStream = valueStreams.get(streamId);
        if (valueStream == null) {
            continue;
        }
        builder.put(streamId, createCheckpointStreamSource(valueStream, checkpoint));
    }
    InputStreamSources rowGroupStreams = new InputStreamSources(builder.buildOrThrow());
    return new RowGroup(groupId, rowOffset, rowCount, minAverageRowBytes, rowGroupStreams);
}
Also used : ValueInputStreamSource(io.trino.orc.stream.ValueInputStreamSource) InputStreamSource(io.trino.orc.stream.InputStreamSource) InputStreamSources(io.trino.orc.stream.InputStreamSources) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) StreamCheckpoint(io.trino.orc.checkpoint.StreamCheckpoint) Checkpoints.getDictionaryStreamCheckpoint(io.trino.orc.checkpoint.Checkpoints.getDictionaryStreamCheckpoint)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)3 Checkpoints.getDictionaryStreamCheckpoint (io.trino.orc.checkpoint.Checkpoints.getDictionaryStreamCheckpoint)3 StreamCheckpoint (io.trino.orc.checkpoint.StreamCheckpoint)3 InputStreamSource (io.trino.orc.stream.InputStreamSource)3 InputStreamSources (io.trino.orc.stream.InputStreamSources)3 ColumnEncodingKind (io.trino.orc.metadata.ColumnEncoding.ColumnEncodingKind)2 OrcColumnId (io.trino.orc.metadata.OrcColumnId)2 OrcTypeKind (io.trino.orc.metadata.OrcType.OrcTypeKind)2 Stream (io.trino.orc.metadata.Stream)2 ValueInputStreamSource (io.trino.orc.stream.ValueInputStreamSource)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Predicates (com.google.common.base.Predicates)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Maps (com.google.common.collect.Maps)1 Slice (io.airlift.slice.Slice)1 AggregatedMemoryContext (io.trino.memory.context.AggregatedMemoryContext)1 Checkpoints.getStreamCheckpoints (io.trino.orc.checkpoint.Checkpoints.getStreamCheckpoints)1