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);
}
}
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);
}
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();
}
}
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;
}
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()));
}
Aggregations