Search in sources :

Example 1 with TaskOutputFactory

use of com.facebook.presto.operator.TaskOutputOperator.TaskOutputFactory in project presto by prestodb.

the class LocalExecutionPlanner method plan.

public LocalExecutionPlan plan(Session session, PlanNode plan, Map<Symbol, Type> types, PartitioningScheme partitioningScheme, 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(SINGLE_DISTRIBUTION) || partitioningScheme.getPartitioning().getHandle().equals(COORDINATOR_DISTRIBUTION)) {
        return plan(session, plan, outputLayout, types, 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(ArgumentBinding::getColumn).map(outputLayout::indexOf).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(session, 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.isReplicateNulls() || partitioningColumns.size() <= 1);
    if (partitioningScheme.isReplicateNulls() && partitioningColumns.size() == 1) {
        nullChannel = OptionalInt.of(outputLayout.indexOf(getOnlyElement(partitioningColumns)));
    }
    return plan(session, plan, outputLayout, types, new PartitionedOutputFactory(partitionFunction, partitionChannels, partitionConstants, nullChannel, outputBuffer, maxPagePartitioningBufferSize));
}
Also used : PartitionFunction(com.facebook.presto.operator.PartitionFunction) Optional(java.util.Optional) NullableValue(com.facebook.presto.spi.predicate.NullableValue) OptionalInt(java.util.OptionalInt) PartitionedOutputFactory(com.facebook.presto.operator.PartitionedOutputOperator.PartitionedOutputFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Type(com.facebook.presto.spi.type.Type) TaskOutputFactory(com.facebook.presto.operator.TaskOutputOperator.TaskOutputFactory)

Aggregations

PartitionFunction (com.facebook.presto.operator.PartitionFunction)1 PartitionedOutputFactory (com.facebook.presto.operator.PartitionedOutputOperator.PartitionedOutputFactory)1 TaskOutputFactory (com.facebook.presto.operator.TaskOutputOperator.TaskOutputFactory)1 NullableValue (com.facebook.presto.spi.predicate.NullableValue)1 Type (com.facebook.presto.spi.type.Type)1 Optional (java.util.Optional)1 OptionalInt (java.util.OptionalInt)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1