YuvalItzchakov commented on a change in pull request #15307: URL: https://github.com/apache/flink/pull/15307#discussion_r608880833
########## File path: flink-table/flink-table-planner-blink/src/test/java/org/apache/flink/table/planner/plan/rules/logical/PushFilterInCalcIntoTableSourceRuleTest.java ########## @@ -0,0 +1,117 @@ +/* + * 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.plan.nodes.FlinkConventions; +import org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCalc; +import org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableSourceScan; +import org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalWatermarkAssigner; +import org.apache.flink.table.planner.plan.optimize.program.FlinkChainedProgram; +import org.apache.flink.table.planner.plan.optimize.program.FlinkHepRuleSetProgramBuilder; +import org.apache.flink.table.planner.plan.optimize.program.FlinkVolcanoProgramBuilder; +import org.apache.flink.table.planner.plan.optimize.program.HEP_RULES_EXECUTION_TYPE; +import org.apache.flink.table.planner.plan.optimize.program.StreamOptimizeContext; +import org.apache.flink.table.planner.utils.StreamTableTestUtil; + +import org.apache.calcite.plan.Convention; +import org.apache.calcite.plan.hep.HepMatchOrder; +import org.apache.calcite.rel.rules.CoreRules; +import org.apache.calcite.tools.RuleSets; +import org.junit.Before; +import org.junit.Test; + +/** Test for {@link PushFilterInCalcIntoTableSourceRuleTest}. */ +public class PushFilterInCalcIntoTableSourceRuleTest extends PushFilterIntoTableSourceScanRuleTest { + + @Before + public void setup() { + util_$eq(streamTestUtil(new TableConfig())); + + FlinkChainedProgram<StreamOptimizeContext> program = new FlinkChainedProgram<>(); + program.addLast( + "Converters", + FlinkVolcanoProgramBuilder.<StreamOptimizeContext>newBuilder() + .add( + RuleSets.ofList( + CoreRules.PROJECT_TO_CALC, + CoreRules.FILTER_TO_CALC, + FlinkCalcMergeRule$.MODULE$.INSTANCE(), + FlinkLogicalCalc.CONVERTER(), + FlinkLogicalTableSourceScan.CONVERTER(), + FlinkLogicalWatermarkAssigner.CONVERTER())) + .setRequiredOutputTraits(new Convention[] {FlinkConventions.LOGICAL()}) + .build()); + program.addLast( + "Filter push in calc down", + FlinkHepRuleSetProgramBuilder.<StreamOptimizeContext>newBuilder() + .setHepRulesExecutionType(HEP_RULES_EXECUTION_TYPE.RULE_SEQUENCE()) + .setHepMatchOrder(HepMatchOrder.BOTTOM_UP) + .add(RuleSets.ofList(PushFilterInCalcIntoTableSourceScanRule.INSTANCE)) + .build()); + ((StreamTableTestUtil) util()).replaceStreamProgram(program); + + String ddl1 = + "CREATE TABLE MyTable (\n" + + " name STRING,\n" + + " id bigint,\n" + + " amount int,\n" + + " price double\n" + + ") WITH (\n" + + " 'connector' = 'values',\n" + + " 'filterable-fields' = 'amount',\n" + + " 'bounded' = 'true'\n" + + ")"; + util().tableEnv().executeSql(ddl1); + + String ddl2 = + "CREATE TABLE VirtualTable (\n" + + " name STRING,\n" + + " id bigint,\n" + + " amount int,\n" + + " virtualField as amount + 1,\n" + + " price double\n" + + ") WITH (\n" + + " 'connector' = 'values',\n" + + " 'filterable-fields' = 'amount',\n" + + " 'bounded' = 'true'\n" + + ")"; + + util().tableEnv().executeSql(ddl2); + Review comment: The thing is `PushFilterIntoLegacyTableSourceScanRuleTest` uses this with `TestLegacyFilterableTableSource.createTemporaryTable` and doesn't create the table explicitly in the DDL. I don't see a big gain here. ########## File path: flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/planner/plan/rules/logical/PushFilterIntoLegacyTableSourceScanRuleTest.xml ########## @@ -185,8 +185,7 @@ LogicalProject(a=[$0], b=[$1]) </Resource> <Resource name="optimized rel plan"> <![CDATA[ -LogicalProject(a=[$0], b=[$1]) -+- LogicalTableScan(table=[[default_catalog, default_database, MTable, source: [filterPushedDown=[true], filter=[and(equals(lower(a), 'foo'), equals(upper(b), 'bar'))]]]]) +LegacyTableSourceScan(table=[[default_catalog, default_database, MTable, source: [filterPushedDown=[true], filter=[and(equals(lower(a), 'foo'), equals(upper(b), 'bar'))]]]], fields=[a, b]) Review comment: I don't know, will check. -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org