xishuaidelin commented on code in PR #24160: URL: https://github.com/apache/flink/pull/24160#discussion_r1465811533
########## flink-table/flink-table-runtime/src/test/java/org/apache/flink/table/runtime/operators/join/stream/StreamingMiniBatchJoinOperatorTest.java: ########## @@ -0,0 +1,1807 @@ +/* + * 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.join.stream; + +import org.apache.flink.streaming.runtime.streamrecord.StreamRecord; +import org.apache.flink.table.data.RowData; +import org.apache.flink.table.runtime.keyselector.RowDataKeySelector; +import org.apache.flink.table.runtime.operators.bundle.trigger.CountCoBundleTrigger; +import org.apache.flink.table.runtime.operators.join.FlinkJoinType; +import org.apache.flink.table.runtime.operators.join.stream.state.JoinInputSideSpec; +import org.apache.flink.table.runtime.typeutils.InternalTypeInfo; +import org.apache.flink.table.types.logical.CharType; +import org.apache.flink.table.types.logical.LogicalType; +import org.apache.flink.table.types.logical.RowType; +import org.apache.flink.table.utils.HandwrittenSelectorUtil; +import org.apache.flink.types.RowKind; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Stream; + +import static org.apache.flink.table.runtime.util.StreamRecordUtils.deleteRecord; +import static org.apache.flink.table.runtime.util.StreamRecordUtils.insertRecord; +import static org.apache.flink.table.runtime.util.StreamRecordUtils.rowOfKind; +import static org.apache.flink.table.runtime.util.StreamRecordUtils.updateAfterRecord; +import static org.apache.flink.table.runtime.util.StreamRecordUtils.updateBeforeRecord; + +/** Test for StreamingMiniBatchJoinOperatorTest. */ +public final class StreamingMiniBatchJoinOperatorTest extends StreamingJoinOperatorTestBase { + + private RowDataKeySelector leftUniqueKeySelector; + private RowDataKeySelector rightUniqueKeySelector; + + @BeforeEach + public void beforeEach(TestInfo testInfo) throws Exception { + rightTypeInfo = + InternalTypeInfo.of( + RowType.of( + new LogicalType[] { + new CharType(false, 20), + new CharType(false, 20), + new CharType(true, 10) + }, + new String[] { + "order_id#", "line_order_id0", "line_order_ship_mode" + })); + + rightKeySelector = + HandwrittenSelectorUtil.getRowDataSelector( + new int[] {1}, + rightTypeInfo.toRowType().getChildren().toArray(new LogicalType[0])); + super.beforeEach(testInfo); + } + + @Tag("miniBatchSize=3") + @Test + public void testLeftJoinWithLeftArriveFirst() throws Exception { + // joinKey is LineOrd + // left fold || right fold + testHarness.processElement1( + insertRecord( + "Ord#1", "LineOrd#2", "3 Bellevue Drive, Pottstown, PA 19464")); // left +I + testHarness.processElement1( + insertRecord( + "Ord#i", + "LineOrd#6", + "i6 Bellevue Drive, Pottstown, Pi 19464")); // left +I + assertor.shouldEmitNothing(testHarness); + testHarness.processElement2(insertRecord("Ord#X", "LineOrd#2", "AIR")); // right + + assertor.shouldEmit( + testHarness, + rowOfKind( + RowKind.INSERT, + "Ord#i", + "LineOrd#6", + "i6 Bellevue Drive, Pottstown, Pi 19464", + null, + null, + null), + rowOfKind( + RowKind.INSERT, + "Ord#1", + "LineOrd#2", + "3 Bellevue Drive, Pottstown, PA 19464", + "Ord#X", + "LineOrd#2", + "AIR")); + } + + @Tag("miniBatchSize=1") + @Test + public void testLeftJoinWithLeftArriveFirstNoMiniBatch() throws Exception { + // joinKey is LineOrd + // left fold || right fold + testHarness.processElement1( + insertRecord( + "Ord#1", "LineOrd#2", "3 Bellevue Drive, Pottstown, PA 19464")); // left +I + + testHarness.processElement1( + insertRecord( + "Ord#i", + "LineOrd#6", + "i6 Bellevue Drive, Pottstown, Pi 19464")); // left +I + testHarness.processElement2(insertRecord("Ord#X", "LineOrd#2", "AIR")); // right + + assertor.shouldEmit( + testHarness, + rowOfKind( + RowKind.INSERT, + "Ord#1", + "LineOrd#2", + "3 Bellevue Drive, Pottstown, PA 19464", + null, + null, + null), + rowOfKind( + RowKind.INSERT, + "Ord#i", + "LineOrd#6", + "i6 Bellevue Drive, Pottstown, Pi 19464", + null, + null, + null), + rowOfKind( + RowKind.DELETE, + "Ord#1", + "LineOrd#2", + "3 Bellevue Drive, Pottstown, PA 19464", + null, + null, + null), + rowOfKind( + RowKind.INSERT, + "Ord#1", + "LineOrd#2", + "3 Bellevue Drive, Pottstown, PA 19464", + "Ord#X", + "LineOrd#2", + "AIR")); + } + + @Tag("miniBatchSize=3") + @Test + public void testRightJoinWithRightArriveFirst() throws Exception { + // joinKey is LineOrd + // left fold || right fold + testHarness.processElement2(insertRecord("Ord#X", "LineOrd#2", "AIR")); // right + + testHarness.processElement1( + insertRecord( + "Ord#1", "LineOrd#2", "3 Bellevue Drive, Pottstown, PA 19464")); // left +I + assertor.shouldEmitNothing(testHarness); + testHarness.processElement1( + insertRecord( + "Ord#i", + "LineOrd#6", + "i6 Bellevue Drive, Pottstown, Pi 19464")); // left +I + + assertor.shouldEmit( + testHarness, + rowOfKind( + RowKind.INSERT, + "Ord#1", + "LineOrd#2", + "3 Bellevue Drive, Pottstown, PA 19464", + "Ord#X", + "LineOrd#2", + "AIR")); + } + + @Tag("miniBatchSize=1") + @Test + public void testRightJoinWithRightArriveFirstWithNoMiniBatch() throws Exception { + // joinKey is LineOrd + // left fold || right fold + testHarness.processElement2(insertRecord("Ord#X", "LineOrd#2", "AIR")); // right + + testHarness.processElement1( + insertRecord( + "Ord#1", "LineOrd#2", "3 Bellevue Drive, Pottstown, PA 19464")); // left +I + testHarness.processElement1( + insertRecord( + "Ord#i", + "LineOrd#6", + "i6 Bellevue Drive, Pottstown, Pi 19464")); // left +I + + assertor.shouldEmit( + testHarness, + rowOfKind(RowKind.INSERT, null, null, null, "Ord#X", "LineOrd#2", "AIR"), + rowOfKind(RowKind.DELETE, null, null, null, "Ord#X", "LineOrd#2", "AIR"), + rowOfKind( + RowKind.INSERT, + "Ord#1", + "LineOrd#2", + "3 Bellevue Drive, Pottstown, PA 19464", + "Ord#X", + "LineOrd#2", + "AIR")); + } + + @Tag("miniBatchSize=3") + @Test + public void testFullJoinWithRightArriveFirst() throws Exception { + // joinKey is LineOrd + // left fold || right fold + testHarness.processElement2(insertRecord("Ord#X", "LineOrd#2", "AIR")); // right + + testHarness.processElement1( + insertRecord( + "Ord#1", "LineOrd#2", "3 Bellevue Drive, Pottstown, PA 19464")); // left +I + assertor.shouldEmitNothing(testHarness); + testHarness.processElement1( + insertRecord( + "Ord#i", + "LineOrd#6", + "i6 Bellevue Drive, Pottstown, Pi 19464")); // left +I + + assertor.shouldEmit( + testHarness, + rowOfKind(RowKind.INSERT, null, null, null, "Ord#X", "LineOrd#2", "AIR"), + rowOfKind( + RowKind.INSERT, + "Ord#i", + "LineOrd#6", + "i6 Bellevue Drive, Pottstown, Pi 19464", + null, + null, + null), + rowOfKind(RowKind.DELETE, null, null, null, "Ord#X", "LineOrd#2", "AIR"), + rowOfKind( + RowKind.INSERT, + "Ord#1", + "LineOrd#2", + "3 Bellevue Drive, Pottstown, PA 19464", + "Ord#X", + "LineOrd#2", + "AIR")); + } + + @Tag("miniBatchSize=1") + @Test + public void testFullJoinWithRightArriveFirstWithNoMiniBatch() throws Exception { + // joinKey is LineOrd + // left fold || right fold Review Comment: Yes, these tests are not supposed to test the fold logic. They are only designed to test the timing-related left and right streams which could avoid emiting redundant records. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
