Search in sources :

Example 1 with ColumnMetadata

use of io.trino.orc.metadata.ColumnMetadata in project trino by trinodb.

the class TestOrcBloomFilters method testMatchesExpandedRange.

@Test
public void testMatchesExpandedRange() {
    Range range = Range.range(BIGINT, 1233L, true, 1235L, true);
    TupleDomainOrcPredicate predicate = TupleDomainOrcPredicate.builder().setBloomFiltersEnabled(true).addColumn(ROOT_COLUMN, Domain.create(ValueSet.ofRanges(range), false)).setDomainCompactionThreshold(100).build();
    ColumnMetadata<ColumnStatistics> matchingStatisticsByColumnIndex = new ColumnMetadata<>(ImmutableList.of(new ColumnStatistics(null, 0, null, new IntegerStatistics(10L, 2000L, null), null, null, null, null, null, null, new Utf8BloomFilterBuilder(1000, 0.01).addLong(1234L).buildBloomFilter())));
    ColumnMetadata<ColumnStatistics> nonMatchingStatisticsByColumnIndex = new ColumnMetadata<>(ImmutableList.of(new ColumnStatistics(null, 0, null, new IntegerStatistics(10L, 2000L, null), null, null, null, null, null, null, new Utf8BloomFilterBuilder(1000, 0.01).addLong(9876L).buildBloomFilter())));
    assertTrue(predicate.matches(1L, matchingStatisticsByColumnIndex));
    assertFalse(predicate.matches(1L, nonMatchingStatisticsByColumnIndex));
}
Also used : ColumnStatistics(io.trino.orc.metadata.statistics.ColumnStatistics) ColumnMetadata(io.trino.orc.metadata.ColumnMetadata) Utf8BloomFilterBuilder(io.trino.orc.metadata.statistics.Utf8BloomFilterBuilder) Range(io.trino.spi.predicate.Range) IntegerStatistics(io.trino.orc.metadata.statistics.IntegerStatistics) Test(org.testng.annotations.Test)

Example 2 with ColumnMetadata

use of io.trino.orc.metadata.ColumnMetadata in project trino by trinodb.

the class TestOrcBloomFilters method testMatches.

@Test
public // simulate query on 2 columns where 1 is used as part of the where, with and without bloom filter
void testMatches() {
    TupleDomainOrcPredicate predicate = TupleDomainOrcPredicate.builder().setBloomFiltersEnabled(true).addColumn(ROOT_COLUMN, Domain.singleValue(BIGINT, 1234L)).build();
    TupleDomainOrcPredicate emptyPredicate = TupleDomainOrcPredicate.builder().build();
    ColumnMetadata<ColumnStatistics> matchingStatisticsByColumnIndex = new ColumnMetadata<>(ImmutableList.of(new ColumnStatistics(null, 0, null, new IntegerStatistics(10L, 2000L, null), null, null, null, null, null, null, new Utf8BloomFilterBuilder(1000, 0.01).addLong(1234L).buildBloomFilter())));
    ColumnMetadata<ColumnStatistics> nonMatchingStatisticsByColumnIndex = new ColumnMetadata<>(ImmutableList.of(new ColumnStatistics(null, 0, null, new IntegerStatistics(10L, 2000L, null), null, null, null, null, null, null, new Utf8BloomFilterBuilder(1000, 0.01).buildBloomFilter())));
    ColumnMetadata<ColumnStatistics> withoutBloomFilterStatisticsByColumnIndex = new ColumnMetadata<>(ImmutableList.of(new ColumnStatistics(null, 0, null, new IntegerStatistics(10L, 2000L, null), null, null, null, null, null, null, null)));
    assertTrue(predicate.matches(1L, matchingStatisticsByColumnIndex));
    assertTrue(predicate.matches(1L, withoutBloomFilterStatisticsByColumnIndex));
    assertFalse(predicate.matches(1L, nonMatchingStatisticsByColumnIndex));
    assertTrue(emptyPredicate.matches(1L, matchingStatisticsByColumnIndex));
}
Also used : ColumnStatistics(io.trino.orc.metadata.statistics.ColumnStatistics) ColumnMetadata(io.trino.orc.metadata.ColumnMetadata) Utf8BloomFilterBuilder(io.trino.orc.metadata.statistics.Utf8BloomFilterBuilder) IntegerStatistics(io.trino.orc.metadata.statistics.IntegerStatistics) Test(org.testng.annotations.Test)

Example 3 with ColumnMetadata

use of io.trino.orc.metadata.ColumnMetadata in project trino by trinodb.

the class TestOrcBloomFilters method testMatchesNonExpandedRange.

@Test
public void testMatchesNonExpandedRange() {
    ColumnMetadata<ColumnStatistics> matchingStatisticsByColumnIndex = new ColumnMetadata<>(ImmutableList.of(new ColumnStatistics(null, 0, null, new IntegerStatistics(10L, 2000L, null), null, null, null, null, null, null, new Utf8BloomFilterBuilder(1000, 0.01).addLong(1500L).buildBloomFilter())));
    Range range = Range.range(BIGINT, 1233L, true, 1235L, true);
    TupleDomainOrcPredicate.TupleDomainOrcPredicateBuilder builder = TupleDomainOrcPredicate.builder().setBloomFiltersEnabled(true).addColumn(ROOT_COLUMN, Domain.create(ValueSet.ofRanges(range), false));
    // Domain expansion doesn't take place -> no bloom filtering -> ranges overlap
    assertTrue(builder.setDomainCompactionThreshold(1).build().matches(1L, matchingStatisticsByColumnIndex));
    assertFalse(builder.setDomainCompactionThreshold(100).build().matches(1L, matchingStatisticsByColumnIndex));
}
Also used : ColumnStatistics(io.trino.orc.metadata.statistics.ColumnStatistics) ColumnMetadata(io.trino.orc.metadata.ColumnMetadata) Utf8BloomFilterBuilder(io.trino.orc.metadata.statistics.Utf8BloomFilterBuilder) Range(io.trino.spi.predicate.Range) IntegerStatistics(io.trino.orc.metadata.statistics.IntegerStatistics) Test(org.testng.annotations.Test)

Example 4 with ColumnMetadata

use of io.trino.orc.metadata.ColumnMetadata in project trino by trinodb.

the class StripeReader method getRowGroupStatistics.

private static ColumnMetadata<ColumnStatistics> getRowGroupStatistics(ColumnMetadata<OrcType> types, Map<StreamId, List<RowGroupIndex>> columnIndexes, int rowGroup) {
    requireNonNull(columnIndexes, "columnIndexes is null");
    checkArgument(rowGroup >= 0, "rowGroup is negative");
    Map<Integer, List<RowGroupIndex>> rowGroupIndexesByColumn = columnIndexes.entrySet().stream().collect(toImmutableMap(entry -> entry.getKey().getColumnId().getId(), Entry::getValue));
    List<ColumnStatistics> statistics = new ArrayList<>(types.size());
    for (int columnIndex = 0; columnIndex < types.size(); columnIndex++) {
        List<RowGroupIndex> rowGroupIndexes = rowGroupIndexesByColumn.get(columnIndex);
        if (rowGroupIndexes != null) {
            statistics.add(rowGroupIndexes.get(rowGroup).getColumnStatistics());
        } else {
            statistics.add(null);
        }
    }
    return new ColumnMetadata<>(statistics);
}
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) ColumnStatistics(io.trino.orc.metadata.statistics.ColumnStatistics) ColumnMetadata(io.trino.orc.metadata.ColumnMetadata) RowGroupIndex(io.trino.orc.metadata.RowGroupIndex) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) StreamCheckpoint(io.trino.orc.checkpoint.StreamCheckpoint) Checkpoints.getDictionaryStreamCheckpoint(io.trino.orc.checkpoint.Checkpoints.getDictionaryStreamCheckpoint)

Example 5 with ColumnMetadata

use of io.trino.orc.metadata.ColumnMetadata 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)

Aggregations

ColumnMetadata (io.trino.orc.metadata.ColumnMetadata)8 ColumnStatistics (io.trino.orc.metadata.statistics.ColumnStatistics)5 ImmutableList (com.google.common.collect.ImmutableList)4 Slice (io.airlift.slice.Slice)4 OrcColumnId (io.trino.orc.metadata.OrcColumnId)4 OrcType (io.trino.orc.metadata.OrcType)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)3 Preconditions.checkState (com.google.common.base.Preconditions.checkState)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 AggregatedMemoryContext (io.trino.memory.context.AggregatedMemoryContext)3 IntegerStatistics (io.trino.orc.metadata.statistics.IntegerStatistics)3 Utf8BloomFilterBuilder (io.trino.orc.metadata.statistics.Utf8BloomFilterBuilder)3 Test (org.testng.annotations.Test)3 Predicates (com.google.common.base.Predicates)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)2 Maps (com.google.common.collect.Maps)2 Checkpoints.getDictionaryStreamCheckpoint (io.trino.orc.checkpoint.Checkpoints.getDictionaryStreamCheckpoint)2 Checkpoints.getStreamCheckpoints (io.trino.orc.checkpoint.Checkpoints.getStreamCheckpoints)2