Search in sources :

Example 1 with DwrfSequenceEncoding

use of com.facebook.presto.orc.metadata.DwrfSequenceEncoding in project presto by prestodb.

the class MapFlatBatchStreamReader method getIntegerKeyBlockTemplate.

private Block getIntegerKeyBlockTemplate(Collection<DwrfSequenceEncoding> sequenceEncodings) {
    Type keyType;
    switch(keyOrcType) {
        case BYTE:
            keyType = TinyintType.TINYINT;
            break;
        case SHORT:
            keyType = SmallintType.SMALLINT;
            break;
        case INT:
            keyType = IntegerType.INTEGER;
            break;
        case LONG:
            keyType = BigintType.BIGINT;
            break;
        default:
            throw new IllegalArgumentException("Unsupported flat map key type: " + keyOrcType);
    }
    BlockBuilder blockBuilder = keyType.createBlockBuilder(null, sequenceEncodings.size());
    for (DwrfSequenceEncoding sequenceEncoding : sequenceEncodings) {
        keyType.writeLong(blockBuilder, sequenceEncoding.getKey().getIntKey());
    }
    return blockBuilder.build();
}
Also used : MapType(com.facebook.presto.common.type.MapType) ReaderUtils.verifyStreamType(com.facebook.presto.orc.reader.ReaderUtils.verifyStreamType) IntegerType(com.facebook.presto.common.type.IntegerType) OrcType(com.facebook.presto.orc.metadata.OrcType) Type(com.facebook.presto.common.type.Type) TinyintType(com.facebook.presto.common.type.TinyintType) BigintType(com.facebook.presto.common.type.BigintType) SmallintType(com.facebook.presto.common.type.SmallintType) VariableWidthBlockBuilder(com.facebook.presto.common.block.VariableWidthBlockBuilder) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) DwrfSequenceEncoding(com.facebook.presto.orc.metadata.DwrfSequenceEncoding)

Example 2 with DwrfSequenceEncoding

use of com.facebook.presto.orc.metadata.DwrfSequenceEncoding in project presto by prestodb.

the class MapFlatBatchStreamReader method startStripe.

@Override
public void startStripe(Stripe stripe) throws IOException {
    presentStreamSource = missingStreamSource(BooleanInputStream.class);
    inMapStreamSources.clear();
    valueStreamDescriptors.clear();
    valueStreamReaders.clear();
    ColumnEncoding encoding = stripe.getColumnEncodings().get(baseValueStreamDescriptor.getStreamId());
    SortedMap<Integer, DwrfSequenceEncoding> additionalSequenceEncodings = Collections.emptySortedMap();
    // encoding or encoding.getAdditionalSequenceEncodings() may not be present when every map is empty or null
    if (encoding != null && encoding.getAdditionalSequenceEncodings().isPresent()) {
        additionalSequenceEncodings = encoding.getAdditionalSequenceEncodings().get();
    }
    // The ColumnEncoding with sequence ID 0 doesn't have any data associated with it
    for (int sequence : additionalSequenceEncodings.keySet()) {
        inMapStreamSources.add(missingStreamSource(BooleanInputStream.class));
        StreamDescriptor valueStreamDescriptor = copyStreamDescriptorWithSequence(baseValueStreamDescriptor, sequence);
        valueStreamDescriptors.add(valueStreamDescriptor);
        BatchStreamReader valueStreamReader = BatchStreamReaders.createStreamReader(type.getValueType(), valueStreamDescriptor, hiveStorageTimeZone, options, systemMemoryContext);
        valueStreamReader.startStripe(stripe);
        valueStreamReaders.add(valueStreamReader);
    }
    keyBlockTemplate = getKeyBlockTemplate(additionalSequenceEncodings.values());
    readOffset = 0;
    nextBatchSize = 0;
    presentStream = null;
    rowGroupOpen = false;
}
Also used : ColumnEncoding(com.facebook.presto.orc.metadata.ColumnEncoding) BooleanInputStream(com.facebook.presto.orc.stream.BooleanInputStream) StreamDescriptor(com.facebook.presto.orc.StreamDescriptor) DwrfSequenceEncoding(com.facebook.presto.orc.metadata.DwrfSequenceEncoding)

Example 3 with DwrfSequenceEncoding

use of com.facebook.presto.orc.metadata.DwrfSequenceEncoding in project presto by prestodb.

the class MapFlatBatchStreamReader method getSliceKeysBlockTemplate.

private Block getSliceKeysBlockTemplate(Collection<DwrfSequenceEncoding> sequenceEncodings) {
    int bytes = 0;
    for (DwrfSequenceEncoding sequenceEncoding : sequenceEncodings) {
        bytes += sequenceEncoding.getKey().getBytesKey().size();
    }
    VariableWidthBlockBuilder builder = new VariableWidthBlockBuilder(null, sequenceEncodings.size(), bytes);
    for (DwrfSequenceEncoding sequenceEncoding : sequenceEncodings) {
        Slice key = Slices.wrappedBuffer(sequenceEncoding.getKey().getBytesKey().toByteArray());
        builder.writeBytes(key, 0, key.length());
        builder.closeEntry();
    }
    return builder.build();
}
Also used : VariableWidthBlockBuilder(com.facebook.presto.common.block.VariableWidthBlockBuilder) Slice(io.airlift.slice.Slice) DwrfSequenceEncoding(com.facebook.presto.orc.metadata.DwrfSequenceEncoding)

Example 4 with DwrfSequenceEncoding

use of com.facebook.presto.orc.metadata.DwrfSequenceEncoding in project presto by prestodb.

the class StripeReader method addIncludedStreams.

/**
 * Add streams that are in includedOrcColumns to the includedStreams map,
 * and return whether there were any rowGroupDictionaries
 */
private boolean addIncludedStreams(Map<Integer, ColumnEncoding> columnEncodings, List<Stream> streams, Map<StreamId, Stream> includedStreams) {
    boolean hasRowGroupDictionary = false;
    for (Stream stream : streams) {
        if (includedOrcColumns.contains(stream.getColumn())) {
            includedStreams.put(new StreamId(stream), stream);
            if (stream.getStreamKind() == StreamKind.IN_DICTIONARY) {
                ColumnEncoding columnEncoding = columnEncodings.get(stream.getColumn());
                if (columnEncoding.getColumnEncodingKind() == DICTIONARY) {
                    hasRowGroupDictionary = true;
                }
                Optional<SortedMap<Integer, DwrfSequenceEncoding>> additionalSequenceEncodings = columnEncoding.getAdditionalSequenceEncodings();
                if (additionalSequenceEncodings.isPresent() && additionalSequenceEncodings.get().values().stream().map(DwrfSequenceEncoding::getValueEncoding).anyMatch(encoding -> encoding.getColumnEncodingKind() == DICTIONARY)) {
                    hasRowGroupDictionary = true;
                }
            }
        }
    }
    return hasRowGroupDictionary;
}
Also used : ColumnEncoding(com.facebook.presto.orc.metadata.ColumnEncoding) StripeEncryptionGroup(com.facebook.presto.orc.metadata.StripeEncryptionGroup) OrcTypeKind(com.facebook.presto.orc.metadata.OrcType.OrcTypeKind) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) INDEX(com.facebook.presto.orc.metadata.Stream.StreamArea.INDEX) RowGroupIndex(com.facebook.presto.orc.metadata.RowGroupIndex) Map(java.util.Map) StripeInformation(com.facebook.presto.orc.metadata.StripeInformation) RuntimeStats(com.facebook.presto.common.RuntimeStats) StreamKind(com.facebook.presto.orc.metadata.Stream.StreamKind) InvalidCheckpointException(com.facebook.presto.orc.checkpoint.InvalidCheckpointException) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) InputStreamSource(com.facebook.presto.orc.stream.InputStreamSource) Collection(java.util.Collection) Set(java.util.Set) CheckpointInputStreamSource.createCheckpointStreamSource(com.facebook.presto.orc.stream.CheckpointInputStreamSource.createCheckpointStreamSource) ValueInputStreamSource(com.facebook.presto.orc.stream.ValueInputStreamSource) ColumnStatistics(com.facebook.presto.orc.metadata.statistics.ColumnStatistics) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) ColumnEncoding(com.facebook.presto.orc.metadata.ColumnEncoding) List(java.util.List) Entry(java.util.Map.Entry) InputStreamSources(com.facebook.presto.orc.stream.InputStreamSources) Optional(java.util.Optional) ValueInputStream(com.facebook.presto.orc.stream.ValueInputStream) DICTIONARY(com.facebook.presto.orc.metadata.ColumnEncoding.ColumnEncodingKind.DICTIONARY) DwrfSequenceEncoding(com.facebook.presto.orc.metadata.DwrfSequenceEncoding) OrcInputStream(com.facebook.presto.orc.stream.OrcInputStream) SortedMap(java.util.SortedMap) DICTIONARY_DATA(com.facebook.presto.orc.metadata.Stream.StreamKind.DICTIONARY_DATA) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) ROW_INDEX(com.facebook.presto.orc.metadata.Stream.StreamKind.ROW_INDEX) Slice(io.airlift.slice.Slice) LENGTH(com.facebook.presto.orc.metadata.Stream.StreamKind.LENGTH) HashMap(java.util.HashMap) Checkpoints.getDictionaryStreamCheckpoint(com.facebook.presto.orc.checkpoint.Checkpoints.getDictionaryStreamCheckpoint) DwrfMetadataReader.toStripeEncryptionGroup(com.facebook.presto.orc.metadata.DwrfMetadataReader.toStripeEncryptionGroup) Multimap(com.google.common.collect.Multimap) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) HiveBloomFilter(com.facebook.presto.orc.metadata.statistics.HiveBloomFilter) HiveWriterVersion(com.facebook.presto.orc.metadata.PostScript.HiveWriterVersion) Objects.requireNonNull(java.util.Objects.requireNonNull) Predicates(com.google.common.base.Predicates) OrcType(com.facebook.presto.orc.metadata.OrcType) Math.toIntExact(java.lang.Math.toIntExact) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ColumnStatistics.mergeColumnStatistics(com.facebook.presto.orc.metadata.statistics.ColumnStatistics.mergeColumnStatistics) BLOOM_FILTER(com.facebook.presto.orc.metadata.Stream.StreamKind.BLOOM_FILTER) NOOP_ORC_LOCAL_MEMORY_CONTEXT(com.facebook.presto.orc.NoopOrcLocalMemoryContext.NOOP_ORC_LOCAL_MEMORY_CONTEXT) SharedBuffer(com.facebook.presto.orc.stream.SharedBuffer) ColumnEncodingKind(com.facebook.presto.orc.metadata.ColumnEncoding.ColumnEncodingKind) DICTIONARY_V2(com.facebook.presto.orc.metadata.ColumnEncoding.ColumnEncodingKind.DICTIONARY_V2) STRUCT(com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.STRUCT) StreamCheckpoint(com.facebook.presto.orc.checkpoint.StreamCheckpoint) IOException(java.io.IOException) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) Maps(com.google.common.collect.Maps) Stream(com.facebook.presto.orc.metadata.Stream) Math.multiplyExact(java.lang.Math.multiplyExact) StripeFooter(com.facebook.presto.orc.metadata.StripeFooter) Checkpoints.getStreamCheckpoints(com.facebook.presto.orc.checkpoint.Checkpoints.getStreamCheckpoints) ValueStreams(com.facebook.presto.orc.stream.ValueStreams) VisibleForTesting(com.google.common.annotations.VisibleForTesting) MetadataReader(com.facebook.presto.orc.metadata.MetadataReader) InputStream(java.io.InputStream) SortedMap(java.util.SortedMap) ValueInputStream(com.facebook.presto.orc.stream.ValueInputStream) OrcInputStream(com.facebook.presto.orc.stream.OrcInputStream) Stream(com.facebook.presto.orc.metadata.Stream) InputStream(java.io.InputStream) DwrfSequenceEncoding(com.facebook.presto.orc.metadata.DwrfSequenceEncoding)

Example 5 with DwrfSequenceEncoding

use of com.facebook.presto.orc.metadata.DwrfSequenceEncoding in project presto by prestodb.

the class MapFlatSelectiveStreamReader method getSliceKeysBlock.

private Block getSliceKeysBlock(List<DwrfSequenceEncoding> sequenceEncodings) {
    int bytes = 0;
    for (DwrfSequenceEncoding sequenceEncoding : sequenceEncodings) {
        bytes += sequenceEncoding.getKey().getBytesKey().size();
    }
    VariableWidthBlockBuilder builder = new VariableWidthBlockBuilder(null, sequenceEncodings.size(), bytes);
    for (int i = 0; i < keyCount; i++) {
        Slice key = Slices.wrappedBuffer(sequenceEncodings.get(keyIndices[i]).getKey().getBytesKey().toByteArray());
        builder.writeBytes(key, 0, key.length());
        builder.closeEntry();
    }
    return builder.build();
}
Also used : VariableWidthBlockBuilder(com.facebook.presto.common.block.VariableWidthBlockBuilder) Slice(io.airlift.slice.Slice) DwrfSequenceEncoding(com.facebook.presto.orc.metadata.DwrfSequenceEncoding)

Aggregations

DwrfSequenceEncoding (com.facebook.presto.orc.metadata.DwrfSequenceEncoding)6 VariableWidthBlockBuilder (com.facebook.presto.common.block.VariableWidthBlockBuilder)3 ColumnEncoding (com.facebook.presto.orc.metadata.ColumnEncoding)3 Slice (io.airlift.slice.Slice)3 StreamDescriptor (com.facebook.presto.orc.StreamDescriptor)2 OrcType (com.facebook.presto.orc.metadata.OrcType)2 BooleanInputStream (com.facebook.presto.orc.stream.BooleanInputStream)2 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 RuntimeStats (com.facebook.presto.common.RuntimeStats)1 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)1 BigintType (com.facebook.presto.common.type.BigintType)1 IntegerType (com.facebook.presto.common.type.IntegerType)1 MapType (com.facebook.presto.common.type.MapType)1 SmallintType (com.facebook.presto.common.type.SmallintType)1 TinyintType (com.facebook.presto.common.type.TinyintType)1 Type (com.facebook.presto.common.type.Type)1 NOOP_ORC_LOCAL_MEMORY_CONTEXT (com.facebook.presto.orc.NoopOrcLocalMemoryContext.NOOP_ORC_LOCAL_MEMORY_CONTEXT)1 Checkpoints.getDictionaryStreamCheckpoint (com.facebook.presto.orc.checkpoint.Checkpoints.getDictionaryStreamCheckpoint)1 Checkpoints.getStreamCheckpoints (com.facebook.presto.orc.checkpoint.Checkpoints.getStreamCheckpoints)1