Search in sources :

Example 6 with Block

use of io.trino.spi.block.Block in project trino by trinodb.

the class PagePartitioner method appendToOutputPartition.

private void appendToOutputPartition(PageBuilder outputPartition, Page page, IntArrayList positions, PositionsAppender[] positionsAppenders) {
    outputPartition.declarePositions(positions.size());
    for (int channel = 0; channel < positionsAppenders.length; channel++) {
        Block partitionBlock = page.getBlock(channel);
        BlockBuilder target = outputPartition.getBlockBuilder(channel);
        positionsAppenders[channel].appendTo(positions, partitionBlock, target);
    }
}
Also used : DictionaryBlock(io.trino.spi.block.DictionaryBlock) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 7 with Block

use of io.trino.spi.block.Block in project trino by trinodb.

the class InputPageProjection method project.

@Override
public Work<Block> project(ConnectorSession session, DriverYieldSignal yieldSignal, Page page, SelectedPositions selectedPositions) {
    Block block = requireNonNull(page, "page is null").getBlock(0);
    requireNonNull(selectedPositions, "selectedPositions is null");
    // TODO: make it lazy when MergePages have better merging heuristics for small lazy pages
    if (selectedPositions.isList()) {
        block = block.copyPositions(selectedPositions.getPositions(), selectedPositions.getOffset(), selectedPositions.size());
    } else if (selectedPositions.size() == block.getPositionCount()) {
        return new CompletedWork<>(block);
    } else {
        block = block.getRegion(selectedPositions.getOffset(), selectedPositions.size());
    }
    return new CompletedWork<>(block);
}
Also used : CompletedWork(io.trino.operator.CompletedWork) Block(io.trino.spi.block.Block)

Example 8 with Block

use of io.trino.spi.block.Block in project trino by trinodb.

the class DynamicFilterSourceOperator method addInput.

@Override
public void addInput(Page page) {
    verify(!finished, "DynamicFilterSourceOperator: addInput() may not be called after finish()");
    current = page;
    if (valueSets == null) {
        if (minValues == null) {
            // there are too many rows to collect min/max range
            return;
        }
        minMaxCollectionLimit -= page.getPositionCount();
        if (minMaxCollectionLimit < 0) {
            handleMinMaxCollectionLimitExceeded();
            return;
        }
        // the predicate became too large, record only min and max values for each orderable channel
        for (int i = 0; i < minMaxChannels.size(); i++) {
            Integer channelIndex = minMaxChannels.get(i);
            BlockPositionComparison comparison = minMaxComparisons.get(i);
            Block block = page.getBlock(channels.get(channelIndex).index);
            updateMinMaxValues(block, channelIndex, comparison);
        }
        return;
    }
    minMaxCollectionLimit -= page.getPositionCount();
    // TODO: we should account for the memory used for collecting build-side values using MemoryContext
    long filterSizeInBytes = 0;
    int filterMaxDistinctValues = 0;
    // Collect only the columns which are relevant for the JOIN.
    for (int channelIndex = 0; channelIndex < channels.size(); ++channelIndex) {
        Block block = page.getBlock(channels.get(channelIndex).index);
        TypedSet valueSet = valueSets[channelIndex];
        for (int position = 0; position < block.getPositionCount(); ++position) {
            valueSet.add(block, position);
        }
        filterSizeInBytes += valueSet.getRetainedSizeInBytes();
        filterMaxDistinctValues = Math.max(filterMaxDistinctValues, valueSet.size());
    }
    if (filterMaxDistinctValues > maxDistinctValues || filterSizeInBytes > maxFilterSizeInBytes) {
        // The whole filter (summed over all columns) exceeds maxFilterSizeInBytes or a column contains too many distinct values
        handleTooLargePredicate();
    }
}
Also used : BlockPositionComparison(io.trino.type.BlockTypeOperators.BlockPositionComparison) Block(io.trino.spi.block.Block) TypedSet.createUnboundedEqualityTypedSet(io.trino.operator.aggregation.TypedSet.createUnboundedEqualityTypedSet) TypedSet(io.trino.operator.aggregation.TypedSet)

Example 9 with Block

use of io.trino.spi.block.Block in project trino by trinodb.

the class DynamicFilterSourceOperator method handleTooLargePredicate.

private void handleTooLargePredicate() {
    // The resulting predicate is too large
    if (minMaxChannels.isEmpty()) {
        // allow all probe-side values to be read.
        dynamicPredicateConsumer.accept(TupleDomain.all());
    } else {
        if (minMaxCollectionLimit < 0) {
            handleMinMaxCollectionLimitExceeded();
        } else {
            // convert to min/max per column for orderable types
            for (int i = 0; i < minMaxChannels.size(); i++) {
                Integer channelIndex = minMaxChannels.get(i);
                BlockPositionComparison comparison = minMaxComparisons.get(i);
                Block block = blockBuilders[channelIndex].build();
                updateMinMaxValues(block, channelIndex, comparison);
            }
        }
    }
    // Drop references to collected values.
    valueSets = null;
    blockBuilders = null;
}
Also used : BlockPositionComparison(io.trino.type.BlockTypeOperators.BlockPositionComparison) Block(io.trino.spi.block.Block)

Example 10 with Block

use of io.trino.spi.block.Block in project trino by trinodb.

the class DynamicFilterSourceOperator method finish.

@Override
public void finish() {
    if (finished) {
        // NOTE: finish() may be called multiple times (see comment at Driver::processInternal).
        return;
    }
    finished = true;
    ImmutableMap.Builder<DynamicFilterId, Domain> domainsBuilder = ImmutableMap.builder();
    if (valueSets == null) {
        if (minValues == null) {
            // else it was notified with 'all' in handleMinMaxCollectionLimitExceeded
            return;
        }
        // valueSets became too large, create TupleDomain from min/max values
        for (Integer channelIndex : minMaxChannels) {
            Type type = channels.get(channelIndex).type;
            if (minValues[channelIndex] == null) {
                // all values were null
                domainsBuilder.put(channels.get(channelIndex).filterId, Domain.none(type));
                continue;
            }
            Object min = readNativeValue(type, minValues[channelIndex], 0);
            Object max = readNativeValue(type, maxValues[channelIndex], 0);
            Domain domain = Domain.create(ValueSet.ofRanges(range(type, min, true, max, true)), false);
            domainsBuilder.put(channels.get(channelIndex).filterId, domain);
        }
        minValues = null;
        maxValues = null;
        dynamicPredicateConsumer.accept(TupleDomain.withColumnDomains(domainsBuilder.buildOrThrow()));
        return;
    }
    for (int channelIndex = 0; channelIndex < channels.size(); ++channelIndex) {
        Block block = blockBuilders[channelIndex].build();
        Type type = channels.get(channelIndex).type;
        domainsBuilder.put(channels.get(channelIndex).filterId, convertToDomain(type, block));
    }
    valueSets = null;
    blockBuilders = null;
    dynamicPredicateConsumer.accept(TupleDomain.withColumnDomains(domainsBuilder.buildOrThrow()));
}
Also used : Type(io.trino.spi.type.Type) Block(io.trino.spi.block.Block) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) ImmutableMap(com.google.common.collect.ImmutableMap) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId)

Aggregations

Block (io.trino.spi.block.Block)520 Test (org.testng.annotations.Test)161 Page (io.trino.spi.Page)145 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)107 BlockBuilder (io.trino.spi.block.BlockBuilder)105 DictionaryBlock (io.trino.spi.block.DictionaryBlock)103 Type (io.trino.spi.type.Type)89 BlockAssertions.createLongsBlock (io.trino.block.BlockAssertions.createLongsBlock)65 Slice (io.airlift.slice.Slice)61 TrinoException (io.trino.spi.TrinoException)41 BlockAssertions.createLongSequenceBlock (io.trino.block.BlockAssertions.createLongSequenceBlock)39 LazyBlock (io.trino.spi.block.LazyBlock)37 ArrayType (io.trino.spi.type.ArrayType)31 RowType (io.trino.spi.type.RowType)31 ArrayList (java.util.ArrayList)31 LongArrayBlock (io.trino.spi.block.LongArrayBlock)29 VariableWidthBlock (io.trino.spi.block.VariableWidthBlock)28 BlockAssertions.createStringsBlock (io.trino.block.BlockAssertions.createStringsBlock)26 ImmutableList (com.google.common.collect.ImmutableList)25 DecimalType (io.trino.spi.type.DecimalType)25