Search in sources :

Example 1 with PartitionedOutputFactory

use of io.trino.operator.output.PartitionedOutputOperator.PartitionedOutputFactory in project trino by trinodb.

the class LocalExecutionPlanner method plan.

public LocalExecutionPlan plan(TaskContext taskContext, PlanNode plan, TypeProvider types, PartitioningScheme partitioningScheme, StageExecutionDescriptor stageExecutionDescriptor, List<PlanNodeId> partitionedSourceOrder, OutputBuffer outputBuffer) {
    List<Symbol> outputLayout = partitioningScheme.getOutputLayout();
    if (partitioningScheme.getPartitioning().getHandle().equals(FIXED_BROADCAST_DISTRIBUTION) || partitioningScheme.getPartitioning().getHandle().equals(FIXED_ARBITRARY_DISTRIBUTION) || partitioningScheme.getPartitioning().getHandle().equals(SCALED_WRITER_DISTRIBUTION) || partitioningScheme.getPartitioning().getHandle().equals(SINGLE_DISTRIBUTION) || partitioningScheme.getPartitioning().getHandle().equals(COORDINATOR_DISTRIBUTION)) {
        return plan(taskContext, stageExecutionDescriptor, plan, outputLayout, types, partitionedSourceOrder, new TaskOutputFactory(outputBuffer));
    }
    // We can convert the symbols directly into channels, because the root must be a sink and therefore the layout is fixed
    List<Integer> partitionChannels;
    List<Optional<NullableValue>> partitionConstants;
    List<Type> partitionChannelTypes;
    if (partitioningScheme.getHashColumn().isPresent()) {
        partitionChannels = ImmutableList.of(outputLayout.indexOf(partitioningScheme.getHashColumn().get()));
        partitionConstants = ImmutableList.of(Optional.empty());
        partitionChannelTypes = ImmutableList.of(BIGINT);
    } else {
        partitionChannels = partitioningScheme.getPartitioning().getArguments().stream().map(argument -> {
            if (argument.isConstant()) {
                return -1;
            }
            return outputLayout.indexOf(argument.getColumn());
        }).collect(toImmutableList());
        partitionConstants = partitioningScheme.getPartitioning().getArguments().stream().map(argument -> {
            if (argument.isConstant()) {
                return Optional.of(argument.getConstant());
            }
            return Optional.<NullableValue>empty();
        }).collect(toImmutableList());
        partitionChannelTypes = partitioningScheme.getPartitioning().getArguments().stream().map(argument -> {
            if (argument.isConstant()) {
                return argument.getConstant().getType();
            }
            return types.get(argument.getColumn());
        }).collect(toImmutableList());
    }
    PartitionFunction partitionFunction = nodePartitioningManager.getPartitionFunction(taskContext.getSession(), partitioningScheme, partitionChannelTypes);
    OptionalInt nullChannel = OptionalInt.empty();
    Set<Symbol> partitioningColumns = partitioningScheme.getPartitioning().getColumns();
    // partitioningColumns expected to have one column in the normal case, and zero columns when partitioning on a constant
    checkArgument(!partitioningScheme.isReplicateNullsAndAny() || partitioningColumns.size() <= 1);
    if (partitioningScheme.isReplicateNullsAndAny() && partitioningColumns.size() == 1) {
        nullChannel = OptionalInt.of(outputLayout.indexOf(getOnlyElement(partitioningColumns)));
    }
    return plan(taskContext, stageExecutionDescriptor, plan, outputLayout, types, partitionedSourceOrder, new PartitionedOutputFactory(partitionFunction, partitionChannels, partitionConstants, partitioningScheme.isReplicateNullsAndAny(), nullChannel, outputBuffer, maxPagePartitioningBufferSize, positionsAppenderFactory));
}
Also used : PartitionFunction(io.trino.operator.PartitionFunction) Optional(java.util.Optional) NullableValue(io.trino.spi.predicate.NullableValue) OptionalInt(java.util.OptionalInt) PartitionedOutputFactory(io.trino.operator.output.PartitionedOutputOperator.PartitionedOutputFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FunctionType(io.trino.type.FunctionType) RowType(io.trino.spi.type.RowType) Type(io.trino.spi.type.Type) TaskOutputFactory(io.trino.operator.output.TaskOutputOperator.TaskOutputFactory)

Aggregations

PartitionFunction (io.trino.operator.PartitionFunction)1 PartitionedOutputFactory (io.trino.operator.output.PartitionedOutputOperator.PartitionedOutputFactory)1 TaskOutputFactory (io.trino.operator.output.TaskOutputOperator.TaskOutputFactory)1 NullableValue (io.trino.spi.predicate.NullableValue)1 RowType (io.trino.spi.type.RowType)1 Type (io.trino.spi.type.Type)1 FunctionType (io.trino.type.FunctionType)1 Optional (java.util.Optional)1 OptionalInt (java.util.OptionalInt)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1