From 520c610c5d837b7900b6876178738976a13e79f2 Mon Sep 17 00:00:00 2001 From: seawinde Date: Tue, 5 Dec 2023 16:52:19 +0800 Subject: [PATCH] [feature](nereids) Support to get related base table info from mv --- .../exploration/mv/MaterializedViewUtils.java | 58 +++++++++++++++++++ .../nereids/trees/plans/PlanVisitorTest.java | 18 ++++++ 2 files changed, 76 insertions(+) create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java new file mode 100644 index 000000000000000..a65df9a65e108bb --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java @@ -0,0 +1,58 @@ +// 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.doris.nereids.rules.exploration.mv; + +import org.apache.doris.mtmv.BaseTableInfo; +import org.apache.doris.nereids.trees.plans.Plan; + +/**The common util for materialized view*/ +public class MaterializedViewUtils { + + /** + * Get related table info which materialized view plan column reference, + * materializedViewPlan should be rewritten plan that sub query should be eliminated + */ + public static RelatedTableInfo getRelatedTableInfo(String column, Plan materializedViewPlan) { + return null; + } + + /**The related table info that mv relate*/ + public static final class RelatedTableInfo { + private BaseTableInfo tableInfo; + private boolean pctPossible; + private String column; + + public RelatedTableInfo(BaseTableInfo tableInfo, boolean pctPossible, String column) { + this.tableInfo = tableInfo; + this.pctPossible = pctPossible; + this.column = column; + } + + public BaseTableInfo getTableInfo() { + return tableInfo; + } + + public boolean isPctPossible() { + return pctPossible; + } + + public String getColumn() { + return column; + } + } +} diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanVisitorTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanVisitorTest.java index c6ca20577cc0704..775bc05e1639a54 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanVisitorTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanVisitorTest.java @@ -21,6 +21,8 @@ import org.apache.doris.catalog.TableIf.TableType; import org.apache.doris.nereids.trees.TreeNode; import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.scalar.CurrentDate; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Now; import org.apache.doris.nereids.trees.expressions.functions.scalar.Random; import org.apache.doris.nereids.trees.expressions.functions.scalar.Uuid; import org.apache.doris.nereids.trees.plans.physical.PhysicalPlan; @@ -142,4 +144,20 @@ public void test2() { expectedTables); }); } + + @Test + public void testTimeFunction() { + PlanChecker.from(connectContext) + .checkExplain("SELECT *, now() FROM table1 " + + "LEFT SEMI JOIN table2 ON table1.c1 = table2.c1 " + + "WHERE table1.c1 IN (SELECT c1 FROM table2) OR CURDATE() < '2023-01-01'", + nereidsPlanner -> { + List> collectResult = new ArrayList<>(); + // Check nondeterministic collect + nereidsPlanner.getAnalyzedPlan().accept(NondeterministicFunctionCollector.INSTANCE, collectResult); + Assertions.assertEquals(2, collectResult.size()); + Assertions.assertTrue(collectResult.get(0) instanceof Now); + Assertions.assertTrue(collectResult.get(1) instanceof CurrentDate); + }); + } }