Skip to content

Commit

Permalink
[feature](nereids) Support to get related base table info from mv
Browse files Browse the repository at this point in the history
  • Loading branch information
seawinde committed Dec 5, 2023
1 parent 6074cdd commit 520c610
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<TreeNode<Expression>> 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);
});
}
}

0 comments on commit 520c610

Please sign in to comment.