pnowojski commented on a change in pull request #11098: [FLINK-16060][task] Implement working StreamMultipleInputProcessor URL: https://github.com/apache/flink/pull/11098#discussion_r382653408
########## File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/transformations/MultipleInputTransformation.java ########## @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.streaming.api.transformations; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.dag.Transformation; +import org.apache.flink.api.java.functions.KeySelector; +import org.apache.flink.streaming.api.operators.ChainingStrategy; +import org.apache.flink.streaming.api.operators.StreamOperatorFactory; + +import org.apache.flink.shaded.guava18.com.google.common.collect.Lists; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +import static org.apache.flink.util.Preconditions.checkState; + +/** + * This Transformation represents the application of a + * {@link org.apache.flink.streaming.api.operators.MultipleInputStreamOperator} + * to input {@code Transformations}. The result is again only one stream. + * + * @param <OUT> The type of the elements that result from this {@code MultipleInputTransformation} + */ +@Internal +public class MultipleInputTransformation<OUT> extends PhysicalTransformation<OUT> { + + private final ArrayList<Transformation<?>> inputs = new ArrayList<>(); + + private final StreamOperatorFactory<OUT> operatorFactory; + + private final ArrayList<KeySelector<?, ?>> stateKeySelectors = new ArrayList<>(); + + private TypeInformation<?> stateKeyType; + + public MultipleInputTransformation( + String name, + StreamOperatorFactory<OUT> operatorFactory, + TypeInformation<OUT> outputType, + int parallelism) { + super(name, outputType, parallelism); + this.operatorFactory = operatorFactory; + } + + public List<Transformation<?>> getInputs() { + return inputs; + } + + /** + * Returns the {@code TypeInformation} for the elements from the inputs. + */ + public List<TypeInformation<?>> getInputTypes() { + return inputs.stream() + .map(Transformation::getOutputType) + .collect(Collectors.toList()); + } + + /** + * Returns the {@code StreamOperatorFactory} of this Transformation. + */ + public StreamOperatorFactory<OUT> getOperatorFactory() { + return operatorFactory; + } + + public void addInput(Transformation<?> input) { + checkState( + stateKeySelectors.isEmpty(), + "Trying to add non-keyed input to keyed transformation."); Review comment: I think it might be a good idea to provide both `MultipleInputTransformation` and `MultipleInputKeyedTransformation` (I was duplicating pre-existing pattern), with some common base class. Maybe for this PR, I would just provide non keyed version, and in the later one, where I'm planning to add actual support for key selectors and multiple input, I would try to add separate class for handling key selectors. This way, if there will come up any reason why having a single class is actually a better idea, we won't have to revert the changes. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
