wanglijie95 commented on code in PR #22966:
URL: https://github.com/apache/flink/pull/22966#discussion_r1260504822


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/optimize/program/FlinkRuntimeFilterProgramTest.java:
##########
@@ -0,0 +1,271 @@
+/*
+ * 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.optimize.program;
+
+import org.apache.flink.configuration.MemorySize;
+import org.apache.flink.table.api.TableConfig;
+import org.apache.flink.table.api.config.OptimizerConfigOptions;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
+import org.apache.flink.table.catalog.stats.CatalogColumnStatisticsDataLong;
+import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
+import org.apache.flink.table.planner.factories.TestValuesCatalog;
+import org.apache.flink.table.planner.utils.BatchTableTestUtil;
+import org.apache.flink.table.planner.utils.TableTestBase;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Collections;
+
+/** Test for {@link FlinkRuntimeFilterProgram}. */
+public class FlinkRuntimeFilterProgramTest extends TableTestBase {
+    // 128L * 1024L * 48 = 6MB
+    private static final long SUITABLE_DIM_ROW_COUNT = 128L * 1024L;
+    // 1024L * 1024L * 1024L * 60 = 60GB
+    private static final long SUITABLE_FACT_ROW_COUNT = 1024L * 1024L * 1024L;
+
+    private final BatchTableTestUtil util = 
batchTestUtil(TableConfig.getDefault());
+    private final TestValuesCatalog catalog =
+            new TestValuesCatalog("testCatalog", "test_database", true);
+
+    @Before
+    public void setup() {
+        catalog.open();
+        util.tableEnv().registerCatalog("testCatalog", catalog);
+        util.tableEnv().useCatalog("testCatalog");
+        TableConfig tableConfig = util.tableEnv().getConfig();
+        
tableConfig.set(OptimizerConfigOptions.TABLE_OPTIMIZER_RUNTIME_FILTER_ENABLED, 
true);
+        tableConfig.set(
+                
OptimizerConfigOptions.TABLE_OPTIMIZER_RUNTIME_FILTER_MAX_BUILD_DATA_SIZE,
+                MemorySize.parse("10m"));
+        tableConfig.set(
+                
OptimizerConfigOptions.TABLE_OPTIMIZER_RUNTIME_FILTER_MIN_PROBE_DATA_SIZE,
+                MemorySize.parse("10g"));
+        tableConfig.set(
+                
OptimizerConfigOptions.TABLE_OPTIMIZER_RUNTIME_FILTER_MIN_FILTER_RATIO, 0.5);
+        util.getTableEnv()
+                .getConfig()
+                
.set(OptimizerConfigOptions.TABLE_OPTIMIZER_BROADCAST_JOIN_THRESHOLD, -1L);
+        util.getTableEnv()
+                .getConfig()
+                
.set(OptimizerConfigOptions.TABLE_OPTIMIZER_AGG_PHASE_STRATEGY, "ONE_PHASE");
+
+        // row avg size is 48
+        String dimDdl =
+                "create table dim (\n"
+                        + "  id BIGINT,\n"
+                        + "  male BOOLEAN,\n"
+                        + "  amount BIGINT,\n"
+                        + "  price BIGINT,\n"
+                        + "  dim_date_sk BIGINT\n"
+                        + ")  with (\n"
+                        + " 'connector' = 'values',\n"
+                        + " 'runtime-source' = 'NewSource',\n"
+                        + " 'bounded' = 'true'\n"
+                        + ")";
+        util.tableEnv().executeSql(dimDdl);
+
+        // row avg size is 60
+        String factDdl =
+                "create table fact (\n"
+                        + "  id BIGINT,\n"
+                        + "  name STRING,\n"
+                        + "  amount BIGINT,\n"
+                        + "  price BIGINT,\n"
+                        + "  fact_date_sk BIGINT\n"
+                        + ") with (\n"
+                        + "  'connector' = 'values',\n"
+                        + "  'runtime-source' = 'NewSource',\n"
+                        + "  'bounded' = 'true'\n"
+                        + ")";
+        util.tableEnv().executeSql(factDdl);
+    }
+
+    @Test
+    public void testSimpleInnerJoin() throws Exception {
+        // runtime filter will succeed
+        setupSuitableTableStatistics();
+        String query = "select * from fact, dim where fact.amount = dim.amount 
and dim.price < 500";
+        util.verifyRelPlan(query);
+        util.verifyExecPlan(query);
+    }
+
+    @Test
+    public void testSemiJoin() throws Exception {
+        // runtime filter will succeed
+        setupSuitableTableStatistics();
+        String query =
+                "select * from fact where fact.fact_date_sk in (select 
dim_date_sk from dim where dim.price < 500)";
+        util.verifyRelPlan(query);
+        util.verifyExecPlan(query);
+    }
+
+    @Test
+    public void testLeftOuterJoinWithLeftBuild() throws Exception {
+        // runtime filter will succeed
+        setupSuitableTableStatistics();
+        String query =
+                "select * from dim left outer join fact on fact.amount = 
dim.amount and dim.price < 500";
+        util.verifyRelPlan(query);
+        util.verifyExecPlan(query);
+    }
+
+    @Test
+    public void testLeftOuterJoinWithRightBuild() throws Exception {
+        // runtime filter will not succeed
+        setupSuitableTableStatistics();
+        String query =
+                "select * from fact left outer join dim on fact.amount = 
dim.amount and dim.price < 500";
+        util.verifyRelPlan(query);
+        util.verifyExecPlan(query);
+    }
+
+    @Test
+    public void testFullOuterJoin() throws Exception {
+        // runtime filter will not succeed
+        setupSuitableTableStatistics();
+        String query =
+                "select * from fact full outer join (select * from dim where 
dim.price < 500) on fact_date_sk = dim_date_sk";
+        util.verifyRelPlan(query);
+        util.verifyExecPlan(query);
+    }
+
+    @Test
+    public void testAntiJoin() throws Exception {
+        // runtime filter will not succeed
+        setupSuitableTableStatistics();
+        String query =
+                "select * from fact where fact.fact_date_sk not in (select 
dim_date_sk from dim where dim.price < 500)";
+        util.verifyRelPlan(query);
+        util.verifyExecPlan(query);
+    }
+
+    @Test
+    public void testNestedLoopJoin() throws Exception {
+        // runtime filter will not succeed
+        setupTableRowCount("dim", 1L);
+        setupTableRowCount("fact", SUITABLE_FACT_ROW_COUNT);
+        String query = "select * from fact, dim where fact.amount = dim.amount 
and dim.price < 500";
+        util.verifyRelPlan(query);
+        util.verifyExecPlan(query);
+    }
+
+    @Test
+    public void testProbeSideIsTooSmall() throws Exception {
+        // runtime filter will not succeed
+        setupTableRowCount("dim", SUITABLE_DIM_ROW_COUNT);
+        // fact is 7.5 GB < 10 GB
+        setupTableRowCount("fact", 128L * 1024L * 1024L);
+        String query = "select * from fact, dim where fact.amount = dim.amount 
and dim.price < 500";
+        util.verifyRelPlan(query);
+        util.verifyExecPlan(query);
+    }
+
+    @Test
+    public void testBuildSideIsTooLarge() throws Exception {
+        // runtime filter will not succeed
+        // dim is 48 MB > 6MB
+        setupTableRowCount("dim", 1024L * 1024L);
+        setupTableRowCount("fact", SUITABLE_FACT_ROW_COUNT);
+        String query = "select * from fact, dim where fact.amount = dim.amount 
and dim.price < 500";
+        util.verifyRelPlan(query);
+        util.verifyExecPlan(query);
+    }
+
+    @Test
+    public void testFilterRatioIsTooSmall() throws Exception {
+        // runtime filter will not succeed
+        setupSuitableTableStatistics();
+        setupTableColumnNdv("dim", "amount", 768L);
+        setupTableColumnNdv("fact", "amount", 1024L);
+        String query = "select * from fact, dim where fact.amount = dim.amount 
and dim.price < 500";
+        util.verifyRelPlan(query);
+        util.verifyExecPlan(query);
+    }
+
+    @Test
+    public void testBuildSideIsJoinWithoutExchange() throws Exception {
+        setupSuitableTableStatistics();
+        util.tableEnv()
+                .executeSql(
+                        "create table fact2 (\n"
+                                + "  id BIGINT,\n"
+                                + "  amount BIGINT,\n"
+                                + "  price BIGINT\n"
+                                + ") with (\n"
+                                + " 'connector' = 'values',\n"
+                                + "  'runtime-source' = 'NewSource',\n"
+                                + " 'bounded' = 'true'\n"
+                                + ")");
+        setupTableRowCount("fact2", SUITABLE_FACT_ROW_COUNT);
+
+        String query =
+                "select * from dim, fact, fact2 where fact.amount = 
fact2.amount and"
+                        + " fact.amount = dim.amount and dim.price < 500";
+        util.verifyRelPlan(query);

Review Comment:
   I hope to verify the `ast`, `opt rel` and `opt exec`. I change it to call 
the `verifyPlan` only.



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to