rionmonster commented on code in PR #29551: URL: https://github.com/apache/flink/pull/29551#discussion_r4790415577
########## flink-table/flink-table-runtime/src/test/java/org/apache/flink/table/runtime/operators/join/stream/multijoin/StreamingMultiJoinNullKeyOperatorTest.java: ########## @@ -0,0 +1,210 @@ +/* + * 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.multijoin; + +import org.apache.flink.runtime.checkpoint.OperatorSubtaskState; +import org.apache.flink.runtime.operators.testutils.MockEnvironment; +import org.apache.flink.table.data.RowData; +import org.apache.flink.table.runtime.generated.GeneratedJoinCondition; +import org.apache.flink.table.runtime.generated.JoinCondition; +import org.apache.flink.table.runtime.operators.join.FlinkJoinType; +import org.apache.flink.table.runtime.operators.join.stream.keyselector.AttributeBasedJoinKeyExtractor.ConditionAttributeRef; +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.types.logical.VarCharType; +import org.apache.flink.testutils.junit.extensions.parameterized.ParameterizedTestExtension; + +import org.junit.jupiter.api.TestTemplate; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests that the multi-way join doesn't store records with a NULL in a field in which a NULL means + * that they can never match, and that its output doesn't change. + * + * <p>SQL: SELECT u.*, o.*, p.* FROM Users u JOIN Orders o ON u.user_id = o.user_id AND u.details = + * o.details LEFT JOIN Payments p ON o.user_id = p.user_id + * + * <p>Schema: Users(user_id PRIMARY KEY, name, details), Orders(user_id, order_id PRIMARY KEY, + * details), Payments(user_id, payment_id PRIMARY KEY, details) + */ +@ExtendWith(ParameterizedTestExtension.class) +class StreamingMultiJoinNullKeyOperatorTest extends StreamingMultiJoinOperatorTestBase { + + // The inner join filters user_id and details of Users and Orders, the left join filters + // user_id of Payments. + private static final int[][] NULL_FILTER_FIELDS = {{0, 2}, {0, 2}, {0}}; + + private boolean filterNulls = true; + + public StreamingMultiJoinNullKeyOperatorTest(StateBackendMode stateBackendMode) { + super( + stateBackendMode, + 3, + List.of(FlinkJoinType.INNER, FlinkJoinType.INNER, FlinkJoinType.LEFT), + Arrays.asList( + null, + createAndCondition(createJoinCondition(1, 0), createDetailsCondition()), + createJoinCondition(2, 1)), + Map.of( + 1, + List.of( + new ConditionAttributeRef(0, 0, 1, 0), + new ConditionAttributeRef(0, 2, 1, 2)), + 2, + List.of(new ConditionAttributeRef(1, 0, 2, 0))), + false); + } + + @TestTemplate + void testDoesNotStoreRecordsThatCanNeverMatch() throws Exception { + insertUser(null, "Gus", "EU"); + insertUser("1", "Bob", null); + insertOrder(null, "order_1", "EU"); + insertOrder("1", "order_2", null); + insertPayment(null, "payment_1", "EU"); + emitsNothing(); + assertThat(testHarness.numKeyedStateEntries()).isZero(); + + deleteUser(null, "Gus", "EU"); + deleteUser("1", "Bob", null); + deleteOrder(null, "order_1", "EU"); + deleteOrder("1", "order_2", null); + deletePayment(null, "payment_1", "EU"); + emitsNothing(); + assertThat(testHarness.numKeyedStateEntries()).isZero(); + } + + @TestTemplate + void testStoresRecordsThatCanMatch() throws Exception { + insertUser("1", "Gus", "EU"); + insertOrder(null, "order_1", "EU"); + insertOrder("1", "order_2", null); + emitsNothing(); + insertOrder("1", "order_3", "EU"); + emits(INSERT, "1", "Gus", "EU", "1", "order_3", "EU", null, null, null); + insertPayment(null, "payment_1", "EU"); + emitsNothing(); + insertPayment("1", "payment_2", null); + emits( + DELETE, + r("1", "Gus", "EU", "1", "order_3", "EU", null, null, null), + INSERT, + r("1", "Gus", "EU", "1", "order_3", "EU", "1", "payment_2", null)); + assertThat(testHarness.numKeyedStateEntries()).isEqualTo(3); + } + + @TestTemplate + void testUpdateAfterReplacesStoredRecord() throws Exception { + // Without UPDATE_BEFORE, as for an input whose unique key contains the common join key Review Comment: I've reworded this and included an additional test (in `testUpsertInputStoresRecordsThatCanNeverMatch`) to cover those known modes which will fail without the guard. -- 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]
