flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [flink] TsReaper commented on a change in pull request #13760: [FLINK-19627][table-runtime] Introduce multiple input operator for batch
Date Fri, 23 Oct 2020 12:15:52 GMT

TsReaper commented on a change in pull request #13760:
URL: https://github.com/apache/flink/pull/13760#discussion_r510828376



##########
File path: flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/input/InputSelectionHandler.java
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.table.runtime.operators.multipleinput.input;
+
+import org.apache.flink.streaming.api.operators.InputSelection;
+import org.apache.flink.streaming.api.operators.MultipleInputStreamOperator;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * This handler is mainly used for selecting the next available input index
+ * according to read priority in {@link MultipleInputStreamOperator}.
+ *
+ * <p>Input read order: the input with high priority (the value of read order is lower)
+ * will be read first, the inputs with same priorities will be read fairly.
+ */
+public class InputSelectionHandler {
+	private final List<InputSpec> inputSpecs;
+	private final int numberOfInput;
+	/**
+	 * All inputs ids sorted by priority.
+	 */
+	private final List<List<Integer>> sortedAvailableInputs;

Review comment:
       nit: use line comment instead of block comment

##########
File path: flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/input/InputSelectionHandler.java
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.table.runtime.operators.multipleinput.input;
+
+import org.apache.flink.streaming.api.operators.InputSelection;
+import org.apache.flink.streaming.api.operators.MultipleInputStreamOperator;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * This handler is mainly used for selecting the next available input index
+ * according to read priority in {@link MultipleInputStreamOperator}.
+ *
+ * <p>Input read order: the input with high priority (the value of read order is lower)
+ * will be read first, the inputs with same priorities will be read fairly.
+ */
+public class InputSelectionHandler {
+	private final List<InputSpec> inputSpecs;
+	private final int numberOfInput;
+	/**
+	 * All inputs ids sorted by priority.
+	 */
+	private final List<List<Integer>> sortedAvailableInputs;
+	private InputSelection inputSelection;
+
+	public InputSelectionHandler(List<InputSpec> inputSpecs) {
+		this.inputSpecs = inputSpecs;
+		this.numberOfInput = inputSpecs.size();
+		this.sortedAvailableInputs = buildSortedAvailableInputs();
+		// read the highest priority inputs first
+		this.inputSelection = buildInputSelection(sortedAvailableInputs.get(0));
+	}
+
+	public InputSelection getInputSelection() {
+		return inputSelection;
+	}
+
+	public void endInput(int inputId) {
+		List<Integer> inputIds = sortedAvailableInputs.get(0);
+		if (!inputIds.remove(Integer.valueOf(inputId))) {
+			throw new RuntimeException("This should not happen.");
+		}
+		if (inputIds.isEmpty()) {
+			// remove the finished input
+			sortedAvailableInputs.remove(0);
+
+			if (sortedAvailableInputs.isEmpty()) {
+				// all input are finished
+				inputIds = null;
+			} else {
+				// read next one
+				inputIds = sortedAvailableInputs.get(0);
+			}
+			inputSelection = buildInputSelection(inputIds);

Review comment:
       `inputIds` might be `null`

##########
File path: flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/input/InputSelectionHandler.java
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.table.runtime.operators.multipleinput.input;
+
+import org.apache.flink.streaming.api.operators.InputSelection;
+import org.apache.flink.streaming.api.operators.MultipleInputStreamOperator;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * This handler is mainly used for selecting the next available input index
+ * according to read priority in {@link MultipleInputStreamOperator}.
+ *
+ * <p>Input read order: the input with high priority (the value of read order is lower)
+ * will be read first, the inputs with same priorities will be read fairly.
+ */
+public class InputSelectionHandler {
+	private final List<InputSpec> inputSpecs;
+	private final int numberOfInput;
+	/**
+	 * All inputs ids sorted by priority.
+	 */
+	private final List<List<Integer>> sortedAvailableInputs;
+	private InputSelection inputSelection;
+
+	public InputSelectionHandler(List<InputSpec> inputSpecs) {
+		this.inputSpecs = inputSpecs;
+		this.numberOfInput = inputSpecs.size();
+		this.sortedAvailableInputs = buildSortedAvailableInputs();
+		// read the highest priority inputs first
+		this.inputSelection = buildInputSelection(sortedAvailableInputs.get(0));
+	}
+
+	public InputSelection getInputSelection() {
+		return inputSelection;
+	}
+
+	public void endInput(int inputId) {
+		List<Integer> inputIds = sortedAvailableInputs.get(0);
+		if (!inputIds.remove(Integer.valueOf(inputId))) {
+			throw new RuntimeException("This should not happen.");
+		}
+		if (inputIds.isEmpty()) {
+			// remove the finished input
+			sortedAvailableInputs.remove(0);
+
+			if (sortedAvailableInputs.isEmpty()) {
+				// all input are finished
+				inputIds = null;
+			} else {
+				// read next one
+				inputIds = sortedAvailableInputs.get(0);
+			}
+			inputSelection = buildInputSelection(inputIds);
+		}
+	}
+
+	private List<List<Integer>> buildSortedAvailableInputs() {
+		final SortedMap<Integer, List<Integer>> orderedAvailableInputIds = new TreeMap<>();
+		for (InputSpec inputSpec : inputSpecs) {
+			List<Integer> inputIds = orderedAvailableInputIds
+					.computeIfAbsent(inputSpec.getReadOrder(), k -> new ArrayList<>());
+			inputIds.add(inputSpec.getMultipleInputId());
+		}
+		return new ArrayList<>(orderedAvailableInputIds.values());
+	}
+
+	private InputSelection buildInputSelection(@Nullable List<Integer> inputIds) {
+		if (inputIds == null) {
+			// TODO throw exception ?
+			return InputSelection.ALL;

Review comment:
       Should be `InputSelection.None` according to the logic of `endInput`?

##########
File path: flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/input/FirstInputOfTwoInput.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.table.runtime.operators.multipleinput.input;
+
+import org.apache.flink.streaming.api.operators.Input;
+import org.apache.flink.streaming.api.operators.TwoInputStreamOperator;
+import org.apache.flink.streaming.api.watermark.Watermark;
+import org.apache.flink.streaming.runtime.streamrecord.LatencyMarker;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.table.data.RowData;
+
+/**
+ * {@link Input} for the first input of {@link SecondInputOfTwoInput}.

Review comment:
       Should be `TwoInputStreamOperator`?

##########
File path: flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/input/SecondInputOfTwoInput.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.table.runtime.operators.multipleinput.input;
+
+import org.apache.flink.streaming.api.operators.Input;
+import org.apache.flink.streaming.api.operators.TwoInputStreamOperator;
+import org.apache.flink.streaming.api.watermark.Watermark;
+import org.apache.flink.streaming.runtime.streamrecord.LatencyMarker;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.table.data.RowData;
+
+/**
+ * {@link Input} for the second input of {@link SecondInputOfTwoInput}.
+ */
+public class SecondInputOfTwoInput extends InputBase {

Review comment:
       ditto

##########
File path: flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/input/InputSelectionHandler.java
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.table.runtime.operators.multipleinput.input;
+
+import org.apache.flink.streaming.api.operators.InputSelection;
+import org.apache.flink.streaming.api.operators.MultipleInputStreamOperator;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * This handler is mainly used for selecting the next available input index
+ * according to read priority in {@link MultipleInputStreamOperator}.
+ *
+ * <p>Input read order: the input with high priority (the value of read order is lower)
+ * will be read first, the inputs with same priorities will be read fairly.
+ */
+public class InputSelectionHandler {
+	private final List<InputSpec> inputSpecs;
+	private final int numberOfInput;
+	/**
+	 * All inputs ids sorted by priority.
+	 */
+	private final List<List<Integer>> sortedAvailableInputs;
+	private InputSelection inputSelection;
+
+	public InputSelectionHandler(List<InputSpec> inputSpecs) {
+		this.inputSpecs = inputSpecs;
+		this.numberOfInput = inputSpecs.size();
+		this.sortedAvailableInputs = buildSortedAvailableInputs();
+		// read the highest priority inputs first
+		this.inputSelection = buildInputSelection(sortedAvailableInputs.get(0));
+	}
+
+	public InputSelection getInputSelection() {
+		return inputSelection;
+	}
+
+	public void endInput(int inputId) {
+		List<Integer> inputIds = sortedAvailableInputs.get(0);
+		if (!inputIds.remove(Integer.valueOf(inputId))) {
+			throw new RuntimeException("This should not happen.");
+		}
+		if (inputIds.isEmpty()) {
+			// remove the finished input
+			sortedAvailableInputs.remove(0);
+
+			if (sortedAvailableInputs.isEmpty()) {
+				// all input are finished
+				inputIds = null;
+			} else {
+				// read next one
+				inputIds = sortedAvailableInputs.get(0);
+			}
+			inputSelection = buildInputSelection(inputIds);
+		}
+	}
+
+	private List<List<Integer>> buildSortedAvailableInputs() {
+		final SortedMap<Integer, List<Integer>> orderedAvailableInputIds = new TreeMap<>();
+		for (InputSpec inputSpec : inputSpecs) {
+			List<Integer> inputIds = orderedAvailableInputIds
+					.computeIfAbsent(inputSpec.getReadOrder(), k -> new ArrayList<>());
+			inputIds.add(inputSpec.getMultipleInputId());
+		}
+		return new ArrayList<>(orderedAvailableInputIds.values());

Review comment:
       Use `LinkedList` instead, as we need to remove its head frequently in `endInput`.

##########
File path: flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/input/InputSelectionHandler.java
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.table.runtime.operators.multipleinput.input;
+
+import org.apache.flink.streaming.api.operators.InputSelection;
+import org.apache.flink.streaming.api.operators.MultipleInputStreamOperator;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * This handler is mainly used for selecting the next available input index
+ * according to read priority in {@link MultipleInputStreamOperator}.
+ *
+ * <p>Input read order: the input with high priority (the value of read order is lower)
+ * will be read first, the inputs with same priorities will be read fairly.
+ */
+public class InputSelectionHandler {
+	private final List<InputSpec> inputSpecs;
+	private final int numberOfInput;
+	/**
+	 * All inputs ids sorted by priority.
+	 */
+	private final List<List<Integer>> sortedAvailableInputs;
+	private InputSelection inputSelection;
+
+	public InputSelectionHandler(List<InputSpec> inputSpecs) {
+		this.inputSpecs = inputSpecs;
+		this.numberOfInput = inputSpecs.size();
+		this.sortedAvailableInputs = buildSortedAvailableInputs();
+		// read the highest priority inputs first
+		this.inputSelection = buildInputSelection(sortedAvailableInputs.get(0));
+	}
+
+	public InputSelection getInputSelection() {
+		return inputSelection;
+	}
+
+	public void endInput(int inputId) {
+		List<Integer> inputIds = sortedAvailableInputs.get(0);
+		if (!inputIds.remove(Integer.valueOf(inputId))) {
+			throw new RuntimeException("This should not happen.");
+		}

Review comment:
       nit: `Preconditions.checkState`?

##########
File path: flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/input/SecondInputOfTwoInput.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.table.runtime.operators.multipleinput.input;
+
+import org.apache.flink.streaming.api.operators.Input;
+import org.apache.flink.streaming.api.operators.TwoInputStreamOperator;
+import org.apache.flink.streaming.api.watermark.Watermark;
+import org.apache.flink.streaming.runtime.streamrecord.LatencyMarker;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.table.data.RowData;
+
+/**
+ * {@link Input} for the second input of {@link SecondInputOfTwoInput}.

Review comment:
       ditto

##########
File path: flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/operators/multipleinput/input/FirstInputOfTwoInput.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.table.runtime.operators.multipleinput.input;
+
+import org.apache.flink.streaming.api.operators.Input;
+import org.apache.flink.streaming.api.operators.TwoInputStreamOperator;
+import org.apache.flink.streaming.api.watermark.Watermark;
+import org.apache.flink.streaming.runtime.streamrecord.LatencyMarker;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.table.data.RowData;
+
+/**
+ * {@link Input} for the first input of {@link SecondInputOfTwoInput}.
+ */
+public class FirstInputOfTwoInput extends InputBase {

Review comment:
       `FirstInputOfTwoInputs`?




----------------------------------------------------------------
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:
users@infra.apache.org



Mime
View raw message