snuyanzin commented on code in PR #27733: URL: https://github.com/apache/flink/pull/27733#discussion_r2891497920
########## flink-table/flink-table-planner/src/test/resources/org/apache/flink/table/planner/plan/rules/logical/SimplifyCoalesceWithEquiJoinConditionRuleTest.xml: ########## @@ -0,0 +1,223 @@ +<?xml version="1.0" ?> +<!-- +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. +--> +<Root> + <TestCase name="testCoalesceOnFullJoinNotSimplified"> + <Resource name="sql"> + <![CDATA[SELECT COALESCE(b.order_id, a.order_id) AS order_id FROM orders a FULL JOIN order_details b ON a.order_id = b.order_id]]> + </Resource> + <Resource name="ast"> + <![CDATA[ +LogicalProject(order_id=[COALESCE($3, $0)]) ++- LogicalJoin(condition=[=($0, $3)], joinType=[full]) + :- LogicalTableScan(table=[[default_catalog, default_database, orders]]) + +- LogicalTableScan(table=[[default_catalog, default_database, order_details]]) +]]> + </Resource> + <Resource name="optimized rel plan"> + <![CDATA[ +Calc(select=[COALESCE(order_id0, order_id) AS order_id]) ++- Join(joinType=[FullOuterJoin], where=[=(order_id, order_id0)], select=[order_id, order_id0], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey]) + :- Exchange(distribution=[hash[order_id]]) + : +- TableSourceScan(table=[[default_catalog, default_database, orders, project=[order_id], metadata=[]]], fields=[order_id]) + +- Exchange(distribution=[hash[order_id]]) + +- TableSourceScan(table=[[default_catalog, default_database, order_details, project=[order_id], metadata=[]]], fields=[order_id]) +]]> + </Resource> + </TestCase> + <TestCase name="testCoalesceOnInnerJoinEquiKey"> + <Resource name="sql"> + <![CDATA[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]]> + </Resource> + <Resource name="ast"> + <![CDATA[ +LogicalProject(order_id=[COALESCE($3, $0)]) ++- LogicalJoin(condition=[=($0, $3)], joinType=[inner]) + :- LogicalTableScan(table=[[default_catalog, default_database, orders]]) + +- LogicalTableScan(table=[[default_catalog, default_database, order_details]]) +]]> + </Resource> + <Resource name="optimized rel plan"> + <![CDATA[ +Calc(select=[order_id0 AS order_id]) ++- Join(joinType=[InnerJoin], where=[=(order_id, order_id0)], select=[order_id, order_id0], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey]) + :- Exchange(distribution=[hash[order_id]]) + : +- TableSourceScan(table=[[default_catalog, default_database, orders, project=[order_id], metadata=[]]], fields=[order_id]) + +- Exchange(distribution=[hash[order_id]]) + +- TableSourceScan(table=[[default_catalog, default_database, order_details, project=[order_id], metadata=[]]], fields=[order_id]) +]]> + </Resource> + </TestCase> + <TestCase name="testCoalesceOnLeftJoinEquiKey"> + <Resource name="sql"> + <![CDATA[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]]> + </Resource> + <Resource name="ast"> + <![CDATA[ +LogicalProject(order_id=[COALESCE($3, $0)], amount=[$2]) ++- LogicalJoin(condition=[=($0, $3)], joinType=[left]) + :- LogicalTableScan(table=[[default_catalog, default_database, orders]]) + +- LogicalTableScan(table=[[default_catalog, default_database, order_details]]) +]]> + </Resource> + <Resource name="optimized rel plan"> + <![CDATA[ +TableSourceScan(table=[[default_catalog, default_database, orders, project=[order_id, amount], metadata=[]]], fields=[order_id, amount]) +]]> + </Resource> + </TestCase> + <TestCase name="testCoalesceOnNestedRowScalarField"> + <Resource name="sql"> + <![CDATA[SELECT CAST(COALESCE(b.r.order_id, a.order_id) AS STRING) AS order_id_str FROM orders a LEFT JOIN order_details_row b ON a.order_id = b.r.order_id]]> + </Resource> + <Resource name="ast"> + <![CDATA[ +LogicalProject(order_id_str=[CAST(COALESCE($3.order_id, $0)):VARCHAR(2147483647) CHARACTER SET "UTF-16LE" NOT NULL]) ++- LogicalProject(order_id=[$0], user_id=[$1], amount=[$2], r=[$3], detail=[$4]) + +- LogicalJoin(condition=[=($0, $5)], joinType=[left]) + :- LogicalTableScan(table=[[default_catalog, default_database, orders]]) + +- LogicalProject(r=[$0], detail=[$1], $f2=[$0.order_id]) + +- LogicalTableScan(table=[[default_catalog, default_database, order_details_row]]) +]]> + </Resource> + <Resource name="optimized rel plan"> + <![CDATA[ +Calc(select=[CAST(r.order_id AS VARCHAR(2147483647)) AS order_id_str]) ++- Join(joinType=[LeftOuterJoin], where=[=(order_id, $f2)], select=[order_id, r, $f2], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[HasUniqueKey]) + :- Exchange(distribution=[hash[order_id]]) + : +- TableSourceScan(table=[[default_catalog, default_database, orders, project=[order_id], metadata=[]]], fields=[order_id]) + +- Exchange(distribution=[hash[$f2]]) + +- Calc(select=[r, r.order_id AS $f2]) + +- TableSourceScan(table=[[default_catalog, default_database, order_details_row, project=[r], metadata=[]]], fields=[r]) +]]> + </Resource> + </TestCase> + <TestCase name="testCoalesceOnNonEquiColumnsNotSimplified"> + <Resource name="sql"> + <![CDATA[SELECT COALESCE(b.detail, CAST(a.amount AS STRING)) AS val FROM orders a LEFT JOIN order_details b ON a.order_id = b.order_id]]> + </Resource> + <Resource name="ast"> + <![CDATA[ +LogicalProject(val=[COALESCE($4, CAST($2):VARCHAR(2147483647) CHARACTER SET "UTF-16LE")]) ++- LogicalJoin(condition=[=($0, $3)], joinType=[left]) + :- LogicalTableScan(table=[[default_catalog, default_database, orders]]) + +- LogicalTableScan(table=[[default_catalog, default_database, order_details]]) +]]> + </Resource> + <Resource name="optimized rel plan"> + <![CDATA[ +Calc(select=[COALESCE(detail, CAST(amount AS VARCHAR(2147483647))) AS val]) ++- Join(joinType=[LeftOuterJoin], where=[=(order_id, order_id0)], select=[order_id, amount, order_id0, detail], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[JoinKeyContainsUniqueKey]) + :- Exchange(distribution=[hash[order_id]]) + : +- TableSourceScan(table=[[default_catalog, default_database, orders, project=[order_id, amount], metadata=[]]], fields=[order_id, amount]) + +- Exchange(distribution=[hash[order_id]]) + +- TableSourceScan(table=[[default_catalog, default_database, order_details]], fields=[order_id, detail]) +]]> + </Resource> + </TestCase> + <TestCase name="testCoalesceOnRightJoinEquiKey"> + <Resource name="sql"> + <![CDATA[SELECT COALESCE(a.order_id, b.order_id) AS order_id FROM orders a RIGHT JOIN order_details b ON a.order_id = b.order_id]]> + </Resource> + <Resource name="ast"> + <![CDATA[ +LogicalProject(order_id=[COALESCE($0, $3)]) ++- LogicalJoin(condition=[=($0, $3)], joinType=[right]) + :- LogicalTableScan(table=[[default_catalog, default_database, orders]]) + +- LogicalTableScan(table=[[default_catalog, default_database, order_details]]) +]]> + </Resource> + <Resource name="optimized rel plan"> + <![CDATA[ +TableSourceScan(table=[[default_catalog, default_database, order_details, project=[order_id], metadata=[]]], fields=[order_id]) Review Comment: ok, it is just left join, then should be ok -- 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]
