rionmonster commented on code in PR #29583:
URL: https://github.com/apache/flink/pull/29583#discussion_r4497521359


##########
flink-table/flink-table-runtime/src/test/java/org/apache/flink/table/runtime/operators/join/stream/multijoin/StreamingMultiJoinUpsertOperatorTest.java:
##########
@@ -0,0 +1,280 @@
+/*
+ * 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.api.common.functions.AbstractRichFunction;
+import org.apache.flink.table.connector.ChangelogMode;
+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.keyselector.RowDataKeySelector;
+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.runtime.util.RuntimeChangelogMode;
+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.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.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests that the multi-way join handles inputs that update a record without 
UPDATE_BEFORE and
+ * delete it with only its unique key. The joined rows and null padding of the 
old version of a
+ * record are retracted.
+ *
+ * <p>SQL: SELECT * 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 AND o.details <> p.details 
LEFT JOIN Shipments s ON
+ * p.user_id = s.user_id AND p.details <> s.details
+ *
+ * <p>Schema: Users(user_id PRIMARY KEY, name, details), Orders, Payments and 
Shipments(user_id, id,
+ * details, PRIMARY KEY (user_id, id)). All inputs are upsert inputs, whose 
keys contain their join
+ * key user_id.
+ */
+@ExtendWith(ParameterizedTestExtension.class)
+class StreamingMultiJoinUpsertOperatorTest extends 
StreamingMultiJoinOperatorTestBase {
+
+    private static final Object[] NO_ROW = {null, null, null};
+    private static final Object[] USER = {"1", "Gus", "A"};
+    private static final Object[] ORDER = {"1", "o1", "B"};
+    private static final Object[] PAYMENT = {"1", "p1", "X"};
+
+    public StreamingMultiJoinUpsertOperatorTest(StateBackendMode 
stateBackendMode) {
+        super(
+                stateBackendMode,
+                4,
+                List.of(
+                        FlinkJoinType.INNER,
+                        FlinkJoinType.INNER,
+                        FlinkJoinType.LEFT,
+                        FlinkJoinType.LEFT),
+                Arrays.asList(
+                        null,
+                        createAndCondition(equalTo(0, 0), notEqualTo(2, 2)),
+                        createAndCondition(equalTo(3, 0), notEqualTo(5, 2)),
+                        createAndCondition(equalTo(6, 0), notEqualTo(8, 2))),
+                Map.of(
+                        1,
+                        List.of(new ConditionAttributeRef(0, 0, 1, 0)),
+                        2,
+                        List.of(new ConditionAttributeRef(1, 0, 2, 0)),
+                        3,
+                        List.of(new ConditionAttributeRef(2, 0, 3, 0))),
+                false);
+    }
+
+    @TestTemplate
+    void testUpdateThatLosesMatchRetractsJoinedRow() throws Exception {
+        insertUserAndOrder();
+
+        updateAfterOrder("1", "o1", "A");
+        emits(DELETE, row(USER, ORDER, NO_ROW, NO_ROW));
+
+        // only the new version of the order is stored
+        updateAfterUser("1", "Gus", "C");
+        emits(UPDATE_AFTER, row(r("1", "Gus", "C"), r("1", "o1", "A"), NO_ROW, 
NO_ROW));
+    }
+
+    @TestTemplate
+    void testInsertThatReplacesStoredRecordRetractsOldVersion() throws 
Exception {
+        insertUserAndOrder();
+
+        insertOrder("1", "o1", "A");
+        emits(DELETE, row(USER, ORDER, NO_ROW, NO_ROW));
+    }
+
+    @TestTemplate
+    void testUpdateOfFirstInputThatLosesMatchRetractsJoinedRow() throws 
Exception {
+        insertUserAndOrder();
+
+        updateAfterUser("1", "Gus", "B");
+        emits(DELETE, row(USER, ORDER, NO_ROW, NO_ROW));
+    }
+
+    @TestTemplate
+    void testUpdateWithSameConditionFieldsUpdatesJoinedRow() throws Exception {
+        insertUserAndOrder();
+
+        updateAfterUser("1", "Bob", "A");
+        emits(UPDATE_AFTER, row(r("1", "Bob", "A"), ORDER, NO_ROW, NO_ROW));
+    }
+
+    @TestTemplate
+    void testKeyOnlyDeleteRetractsStoredRecord() throws Exception {
+        insertUserAndOrder();
+
+        deleteOrder("1", "o1", null);
+        emits(DELETE, row(USER, ORDER, NO_ROW, NO_ROW));
+        assertThat(testHarness.numKeyedStateEntries()).isOne();

Review Comment:
   Thanks! I think this one snuck in with one of the previously stacked PRs, 
not sure how it was missed. I've made these updates and folded the fix into the 
original commit (so that every commit compiles).



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

Reply via email to