snuyanzin commented on code in PR #27733: URL: https://github.com/apache/flink/pull/27733#discussion_r2882786006
########## flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/rules/logical/SimplifyCoalesceWithEquiJoinConditionRuleTest.java: ########## @@ -0,0 +1,136 @@ +/* + * 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.planner.plan.rules.logical; + +import org.apache.flink.table.api.TableConfig; +import org.apache.flink.table.planner.utils.StreamTableTestUtil; +import org.apache.flink.table.planner.utils.TableTestBase; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** Test rule {@link SimplifyCoalesceWithEquiJoinConditionRule}. */ +class SimplifyCoalesceWithEquiJoinConditionRuleTest extends TableTestBase { + + private StreamTableTestUtil util; + + @BeforeEach + void before() { + util = streamTestUtil(TableConfig.getDefault()); + + util.tableEnv() + .executeSql( + "CREATE TABLE orders (" + + " order_id BIGINT NOT NULL," + + " user_id BIGINT NOT NULL," + + " amount DOUBLE," + + " PRIMARY KEY (order_id) NOT ENFORCED" + + ") WITH ('connector' = 'values')"); + + util.tableEnv() + .executeSql( + "CREATE TABLE order_details (" + + " order_id BIGINT NOT NULL," + + " detail STRING," + + " PRIMARY KEY (order_id) NOT ENFORCED" + + ") WITH ('connector' = 'values')"); + + util.tableEnv() + .executeSql( + "CREATE TABLE composite_key_table (" + + " k1 BIGINT NOT NULL," + + " k2 BIGINT NOT NULL," + + " val STRING," + + " PRIMARY KEY (k1, k2) NOT ENFORCED" + + ") WITH ('connector' = 'values')"); + + util.tableEnv() + .executeSql( + "CREATE TABLE composite_key_details (" + + " k1 BIGINT NOT NULL," + + " k2 BIGINT NOT NULL," + + " info STRING," + + " PRIMARY KEY (k1, k2) NOT ENFORCED" + + ") WITH ('connector' = 'values')"); + } + + @Test + void testCoalesceOnLeftJoinEquiKey() { + util.verifyRelPlan( + "SELECT COALESCE(b.order_id, a.order_id) AS order_id, a.amount " + + "FROM orders a LEFT JOIN order_details b ON a.order_id = b.order_id"); + } + + @Test + void testCoalesceReversedArgsOnLeftJoin() { + util.verifyRelPlan( + "SELECT COALESCE(a.order_id, b.order_id) AS order_id, a.amount " + + "FROM orders a LEFT JOIN order_details b ON a.order_id = b.order_id"); + } + + @Test + void testCoalesceOnInnerJoinEquiKey() { + util.verifyRelPlan( + "SELECT COALESCE(b.order_id, a.order_id) AS order_id " + + "FROM orders a INNER JOIN order_details b ON a.order_id = b.order_id"); Review Comment: what about cases with `COALESCE` in condition? is it out of scope? -- 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]
