pnowojski commented on a change in pull request #11098: [FLINK-16060][task] 
Implement working StreamMultipleInputProcessor
URL: https://github.com/apache/flink/pull/11098#discussion_r383381055
 
 

 ##########
 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.");
+               inputs.add(input);
+       }
+
+       public void addInput(Transformation<?> input, KeySelector<?, ?> 
keySelector) {
+               checkState(
+                       stateKeySelectors.size() == inputs.size(),
+                       "Trying to add keyed input to non-keyed 
transformation");
+               inputs.add(input);
+               stateKeySelectors.add(keySelector);
+       }
+
+       public List<KeySelector<?, ?>> getStateKeySelectors() {
+               return stateKeySelectors;
+       }
+
+       public void setStateKeyType(TypeInformation<?> stateKeyType) {
+               this.stateKeyType = stateKeyType;
+       }
+
+       public TypeInformation<?> getStateKeyType() {
+               return stateKeyType;
+       }
+
+       @Override
+       public Collection<Transformation<?>> getTransitivePredecessors() {
+               List<Transformation<?>> result = Lists.newArrayList();
 
 Review comment:
   Bah, I don't like going back and forth between collections and streams. 
Especially in flatMap. But ok ;)

----------------------------------------------------------------
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

Reply via email to