Search in sources :

Example 1 with InputProperty

use of org.apache.flink.table.planner.plan.nodes.exec.InputProperty in project flink by apache.

the class StreamExecExchange method translateToPlanInternal.

@SuppressWarnings("unchecked")
@Override
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
    final Transformation<RowData> inputTransform = (Transformation<RowData>) getInputEdges().get(0).translateToPlan(planner);
    final StreamPartitioner<RowData> partitioner;
    final int parallelism;
    final InputProperty inputProperty = getInputProperties().get(0);
    final InputProperty.DistributionType distributionType = inputProperty.getRequiredDistribution().getType();
    switch(distributionType) {
        case SINGLETON:
            partitioner = new GlobalPartitioner<>();
            parallelism = 1;
            break;
        case HASH:
            // TODO Eliminate duplicate keys
            int[] keys = ((HashDistribution) inputProperty.getRequiredDistribution()).getKeys();
            InternalTypeInfo<RowData> inputType = (InternalTypeInfo<RowData>) inputTransform.getOutputType();
            RowDataKeySelector keySelector = KeySelectorUtil.getRowDataSelector(keys, inputType);
            partitioner = new KeyGroupStreamPartitioner<>(keySelector, DEFAULT_LOWER_BOUND_MAX_PARALLELISM);
            parallelism = ExecutionConfig.PARALLELISM_DEFAULT;
            break;
        default:
            throw new TableException(String.format("%s is not supported now!", distributionType));
    }
    final Transformation<RowData> transformation = new PartitionTransformation<>(inputTransform, partitioner);
    createTransformationMeta(EXCHANGE_TRANSFORMATION, config).fill(transformation);
    transformation.setParallelism(parallelism);
    transformation.setOutputType(InternalTypeInfo.of(getOutputType()));
    return transformation;
}
Also used : PartitionTransformation(org.apache.flink.streaming.api.transformations.PartitionTransformation) Transformation(org.apache.flink.api.dag.Transformation) TableException(org.apache.flink.table.api.TableException) InputProperty(org.apache.flink.table.planner.plan.nodes.exec.InputProperty) PartitionTransformation(org.apache.flink.streaming.api.transformations.PartitionTransformation) HashDistribution(org.apache.flink.table.planner.plan.nodes.exec.InputProperty.HashDistribution) InternalTypeInfo(org.apache.flink.table.runtime.typeutils.InternalTypeInfo) RowData(org.apache.flink.table.data.RowData) RowDataKeySelector(org.apache.flink.table.runtime.keyselector.RowDataKeySelector)

Example 2 with InputProperty

use of org.apache.flink.table.planner.plan.nodes.exec.InputProperty in project flink by apache.

the class BatchExecMultipleInput method translateToPlanInternal.

@Override
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
    final List<Transformation<?>> inputTransforms = new ArrayList<>();
    for (ExecEdge inputEdge : getInputEdges()) {
        inputTransforms.add(inputEdge.translateToPlan(planner));
    }
    final Transformation<?> outputTransform = rootNode.translateToPlan(planner);
    final int[] readOrders = getInputProperties().stream().map(InputProperty::getPriority).mapToInt(i -> i).toArray();
    final TableOperatorWrapperGenerator generator = new TableOperatorWrapperGenerator(inputTransforms, outputTransform, readOrders);
    generator.generate();
    final List<Pair<Transformation<?>, InputSpec>> inputTransformAndInputSpecPairs = generator.getInputTransformAndInputSpecPairs();
    final MultipleInputTransformation<RowData> multipleInputTransform = new MultipleInputTransformation<>(createTransformationName(config), new BatchMultipleInputStreamOperatorFactory(inputTransformAndInputSpecPairs.stream().map(Pair::getValue).collect(Collectors.toList()), generator.getHeadWrappers(), generator.getTailWrapper()), InternalTypeInfo.of(getOutputType()), generator.getParallelism());
    multipleInputTransform.setDescription(createTransformationDescription(config));
    inputTransformAndInputSpecPairs.forEach(input -> multipleInputTransform.addInput(input.getKey()));
    if (generator.getMaxParallelism() > 0) {
        multipleInputTransform.setMaxParallelism(generator.getMaxParallelism());
    }
    // set resources
    multipleInputTransform.setResources(generator.getMinResources(), generator.getPreferredResources());
    final int memoryWeight = generator.getManagedMemoryWeight();
    final long memoryBytes = (long) memoryWeight << 20;
    ExecNodeUtil.setManagedMemoryWeight(multipleInputTransform, memoryBytes);
    // set chaining strategy for source chaining
    multipleInputTransform.setChainingStrategy(ChainingStrategy.HEAD_WITH_SOURCES);
    return multipleInputTransform;
}
Also used : MultipleInputTransformation(org.apache.flink.streaming.api.transformations.MultipleInputTransformation) ExecNodeContext(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeContext) RowData(org.apache.flink.table.data.RowData) PlannerBase(org.apache.flink.table.planner.delegation.PlannerBase) InputProperty(org.apache.flink.table.planner.plan.nodes.exec.InputProperty) SingleTransformationTranslator(org.apache.flink.table.planner.plan.nodes.exec.SingleTransformationTranslator) ExecNodeConfig(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeConfig) InputSpec(org.apache.flink.table.runtime.operators.multipleinput.input.InputSpec) Collectors(java.util.stream.Collectors) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode) BatchMultipleInputStreamOperatorFactory(org.apache.flink.table.runtime.operators.multipleinput.BatchMultipleInputStreamOperatorFactory) TableOperatorWrapperGenerator(org.apache.flink.table.runtime.operators.multipleinput.TableOperatorWrapperGenerator) ArrayList(java.util.ArrayList) ExecNodeUtil(org.apache.flink.table.planner.plan.nodes.exec.utils.ExecNodeUtil) List(java.util.List) InternalTypeInfo(org.apache.flink.table.runtime.typeutils.InternalTypeInfo) ChainingStrategy(org.apache.flink.streaming.api.operators.ChainingStrategy) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) Pair(org.apache.commons.lang3.tuple.Pair) Preconditions.checkArgument(org.apache.flink.util.Preconditions.checkArgument) ExecNodeBase(org.apache.flink.table.planner.plan.nodes.exec.ExecNodeBase) Transformation(org.apache.flink.api.dag.Transformation) MultipleInputTransformation(org.apache.flink.streaming.api.transformations.MultipleInputTransformation) Transformation(org.apache.flink.api.dag.Transformation) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) InputProperty(org.apache.flink.table.planner.plan.nodes.exec.InputProperty) ArrayList(java.util.ArrayList) BatchMultipleInputStreamOperatorFactory(org.apache.flink.table.runtime.operators.multipleinput.BatchMultipleInputStreamOperatorFactory) TableOperatorWrapperGenerator(org.apache.flink.table.runtime.operators.multipleinput.TableOperatorWrapperGenerator) RowData(org.apache.flink.table.data.RowData) MultipleInputTransformation(org.apache.flink.streaming.api.transformations.MultipleInputTransformation) Pair(org.apache.commons.lang3.tuple.Pair)

Example 3 with InputProperty

use of org.apache.flink.table.planner.plan.nodes.exec.InputProperty in project flink by apache.

the class MultipleInputNodeCreationProcessor method createStreamMultipleInputNode.

private StreamExecMultipleInput createStreamMultipleInputNode(MultipleInputGroup group, List<Tuple3<ExecNode<?>, InputProperty, ExecEdge>> inputs) {
    ExecNode<?> rootNode = group.root.execNode;
    List<ExecNode<?>> inputNodes = new ArrayList<>();
    for (Tuple3<ExecNode<?>, InputProperty, ExecEdge> tuple3 : inputs) {
        inputNodes.add(tuple3.f0);
    }
    String description = ExecNodeUtil.getMultipleInputDescription(rootNode, inputNodes, new ArrayList<>());
    StreamExecMultipleInput multipleInput = new StreamExecMultipleInput(inputNodes.stream().map(i -> InputProperty.DEFAULT).collect(Collectors.toList()), rootNode, description);
    List<ExecEdge> inputEdges = new ArrayList<>(inputNodes.size());
    for (ExecNode<?> inputNode : inputNodes) {
        inputEdges.add(ExecEdge.builder().source(inputNode).target(multipleInput).build());
    }
    multipleInput.setInputEdges(inputEdges);
    return multipleInput;
}
Also used : InputProperty(org.apache.flink.table.planner.plan.nodes.exec.InputProperty) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) ArrayList(java.util.ArrayList) StreamExecMultipleInput(org.apache.flink.table.planner.plan.nodes.exec.stream.StreamExecMultipleInput) ExecNode(org.apache.flink.table.planner.plan.nodes.exec.ExecNode)

Example 4 with InputProperty

use of org.apache.flink.table.planner.plan.nodes.exec.InputProperty in project flink by apache.

the class MultipleInputNodeCreationProcessor method createMultipleInputNode.

private ExecNode<?> createMultipleInputNode(MultipleInputGroup group, Map<ExecNodeWrapper, ExecNode<?>> visitedMap) {
    // calculate the inputs of the multiple input node
    List<Tuple3<ExecNode<?>, InputProperty, ExecEdge>> inputs = new ArrayList<>();
    for (ExecNodeWrapper member : group.members) {
        for (int i = 0; i < member.inputs.size(); i++) {
            ExecNodeWrapper memberInput = member.inputs.get(i);
            if (group.members.contains(memberInput)) {
                continue;
            }
            Preconditions.checkState(visitedMap.containsKey(memberInput), "Input of a multiple input member is not visited. This is a bug.");
            ExecNode<?> inputNode = visitedMap.get(memberInput);
            InputProperty inputProperty = member.execNode.getInputProperties().get(i);
            ExecEdge edge = member.execNode.getInputEdges().get(i);
            inputs.add(Tuple3.of(inputNode, inputProperty, edge));
        }
    }
    if (isStreaming) {
        return createStreamMultipleInputNode(group, inputs);
    } else {
        return createBatchMultipleInputNode(group, inputs);
    }
}
Also used : InputProperty(org.apache.flink.table.planner.plan.nodes.exec.InputProperty) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) Tuple3(org.apache.flink.api.java.tuple.Tuple3) ArrayList(java.util.ArrayList)

Example 5 with InputProperty

use of org.apache.flink.table.planner.plan.nodes.exec.InputProperty in project flink by apache.

the class InputPriorityConflictResolver method resolveInputPriorityConflict.

@Override
protected void resolveInputPriorityConflict(ExecNode<?> node, int higherInput, int lowerInput) {
    ExecNode<?> higherNode = node.getInputEdges().get(higherInput).getSource();
    ExecNode<?> lowerNode = node.getInputEdges().get(lowerInput).getSource();
    final ExecNode<?> newNode;
    if (lowerNode instanceof BatchExecExchange) {
        BatchExecExchange exchange = (BatchExecExchange) lowerNode;
        InputProperty inputEdge = exchange.getInputProperties().get(0);
        InputProperty inputProperty = InputProperty.builder().requiredDistribution(inputEdge.getRequiredDistribution()).priority(inputEdge.getPriority()).damBehavior(getDamBehavior()).build();
        if (isConflictCausedByExchange(higherNode, exchange)) {
            // special case: if exchange is exactly the reuse node,
            // we should split it into two nodes
            BatchExecExchange newExchange = new BatchExecExchange(inputProperty, (RowType) exchange.getOutputType(), "Exchange");
            newExchange.setRequiredExchangeMode(exchangeMode);
            newExchange.setInputEdges(exchange.getInputEdges());
            newNode = newExchange;
        } else {
            // create new BatchExecExchange with new inputProperty
            BatchExecExchange newExchange = new BatchExecExchange(inputProperty, (RowType) exchange.getOutputType(), exchange.getDescription());
            newExchange.setRequiredExchangeMode(exchangeMode);
            newExchange.setInputEdges(exchange.getInputEdges());
            newNode = newExchange;
        }
    } else {
        newNode = createExchange(node, lowerInput);
    }
    ExecEdge newEdge = ExecEdge.builder().source(newNode).target(node).build();
    node.replaceInputEdge(lowerInput, newEdge);
}
Also used : InputProperty(org.apache.flink.table.planner.plan.nodes.exec.InputProperty) ExecEdge(org.apache.flink.table.planner.plan.nodes.exec.ExecEdge) BatchExecExchange(org.apache.flink.table.planner.plan.nodes.exec.batch.BatchExecExchange)

Aggregations

InputProperty (org.apache.flink.table.planner.plan.nodes.exec.InputProperty)11 ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)8 ArrayList (java.util.ArrayList)6 ExecNode (org.apache.flink.table.planner.plan.nodes.exec.ExecNode)5 Transformation (org.apache.flink.api.dag.Transformation)3 TableException (org.apache.flink.table.api.TableException)3 RowData (org.apache.flink.table.data.RowData)3 PartitionTransformation (org.apache.flink.streaming.api.transformations.PartitionTransformation)2 HashDistribution (org.apache.flink.table.planner.plan.nodes.exec.InputProperty.HashDistribution)2 RequiredDistribution (org.apache.flink.table.planner.plan.nodes.exec.InputProperty.RequiredDistribution)2 BatchExecExchange (org.apache.flink.table.planner.plan.nodes.exec.batch.BatchExecExchange)2 AbstractExecNodeExactlyOnceVisitor (org.apache.flink.table.planner.plan.nodes.exec.visitor.AbstractExecNodeExactlyOnceVisitor)2 InternalTypeInfo (org.apache.flink.table.runtime.typeutils.InternalTypeInfo)2 StringWriter (java.io.StringWriter)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Pair (org.apache.commons.lang3.tuple.Pair)1 VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)1