seawinde commented on code in PR #27922: URL: https://github.com/apache/doris/pull/27922#discussion_r1416992812
########## fe/fe-core/src/main/java/org/apache/doris/mtmv/MVCache.java: ########## @@ -0,0 +1,80 @@ +// 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.mtmv; + +import org.apache.doris.catalog.MTMV; +import org.apache.doris.nereids.NereidsPlanner; +import org.apache.doris.nereids.StatementContext; +import org.apache.doris.nereids.parser.NereidsParser; +import org.apache.doris.nereids.properties.PhysicalProperties; +import org.apache.doris.nereids.trees.expressions.NamedExpression; +import org.apache.doris.nereids.trees.plans.Plan; +import org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel; +import org.apache.doris.nereids.trees.plans.logical.LogicalPlan; +import org.apache.doris.nereids.trees.plans.logical.LogicalResultSink; +import org.apache.doris.qe.ConnectContext; +import org.apache.doris.qe.OriginStatement; + +import java.util.List; +import java.util.stream.Collectors; + +/**The cache for materialized view cache */ +public class MVCache { + + // the materialized view plan which should be optimized by the same rules to query + private final Plan logicalPlan; + // this should be shuttle expression with lineage + private final List<NamedExpression> mvOutputExpressions; + // the context when parse, analyze, optimize the mv logical plan + + public MVCache(MTMV materializedView, Plan logicalPlan, List<NamedExpression> mvOutputExpressions) { + this.logicalPlan = logicalPlan; + this.mvOutputExpressions = mvOutputExpressions; + } + + public Plan getLogicalPlan() { + return logicalPlan; + } + + public List<NamedExpression> getMvOutputExpressions() { + return mvOutputExpressions; + } + + public MVCache(Plan logicalPlan, List<NamedExpression> mvOutputExpressions) { + this.logicalPlan = logicalPlan; + this.mvOutputExpressions = mvOutputExpressions; + } + + public static MVCache from(MTMV mtmv, ConnectContext connectContext) { + LogicalPlan unboundMvPlan = new NereidsParser().parseSingle(mtmv.getQuerySql()); + // TODO: connect context set current db when create mv by use database + StatementContext mvSqlStatementContext = new StatementContext(connectContext, + new OriginStatement(mtmv.getQuerySql(), 0)); + NereidsPlanner planner = new NereidsPlanner(mvSqlStatementContext); + + planner.plan(unboundMvPlan, PhysicalProperties.ANY, ExplainLevel.ALL_PLAN); + Plan mvAnalyzedPlan = planner.getAnalyzedPlan(); + Plan mvRewrittenPlan = planner.getRewrittenPlan(); + Plan mvPlan = mvRewrittenPlan instanceof LogicalResultSink Review Comment: yeah, you are right -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org