starocean999 commented on code in PR #43152: URL: https://github.com/apache/doris/pull/43152#discussion_r1830814637
########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCreateMaterializedViewCommand.java: ########## @@ -0,0 +1,157 @@ +// 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.trees.plans.commands; + +import org.apache.doris.analysis.Analyzer; +import org.apache.doris.analysis.StmtType; +import org.apache.doris.analysis.TableName; +import org.apache.doris.catalog.Column; +import org.apache.doris.catalog.DatabaseIf; +import org.apache.doris.catalog.Env; +import org.apache.doris.catalog.MaterializedIndexMeta; +import org.apache.doris.catalog.OlapTable; +import org.apache.doris.catalog.ScalarType; +import org.apache.doris.catalog.TableIf; +import org.apache.doris.common.AnalysisException; +import org.apache.doris.common.ErrorCode; +import org.apache.doris.common.ErrorReport; +import org.apache.doris.common.util.Util; +import org.apache.doris.mysql.privilege.PrivPredicate; +import org.apache.doris.nereids.trees.plans.PlanType; +import org.apache.doris.nereids.trees.plans.commands.info.TableNameInfo; +import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor; +import org.apache.doris.qe.ConnectContext; +import org.apache.doris.qe.ShowResultSet; +import org.apache.doris.qe.ShowResultSetMetaData; +import org.apache.doris.qe.StmtExecutor; + +import com.google.common.collect.Lists; + +import java.util.List; + +/** + * Represents the command for SHOW CREATE MATERIALIZED VIEW. + */ +public class ShowCreateMaterializedViewCommand extends Command implements NoForward { + private static final ShowResultSetMetaData MATERIALIZED_VIEW_META_DATA = + ShowResultSetMetaData.builder() + .addColumn(new Column("TableName", ScalarType.createVarchar(20))) + .addColumn(new Column("ViewName", ScalarType.createVarchar(30))) + .addColumn(new Column("CreateStmt", ScalarType.createVarchar(500))) + .build(); + + private final String dbName; + private final String mvName; + private final String tableName; + private final String catalog; + + public ShowCreateMaterializedViewCommand(String mvName, TableNameInfo tableNameInfo) { + super(PlanType.SHOW_CREATE_MATERIALIZED_VIEW_COMMAND); + this.tableName = tableNameInfo.getTbl(); + this.dbName = tableNameInfo.getDb(); + this.catalog = tableNameInfo.getCtl(); + this.mvName = mvName; + } + + private void validate(ConnectContext ctx) throws AnalysisException { + TableName tbl = new TableName(catalog, dbName, tableName); + + Analyzer analyzer = new Analyzer(ctx.getEnv(), ctx); + tbl.analyze(analyzer); + + // disallow external catalog + Util.prohibitExternalCatalog(tbl.getCtl(), this.getClass().getSimpleName()); + if (!Env.getCurrentEnv().getAccessManager() + .checkTblPriv(ConnectContext.get(), tbl.getCtl(), tbl.getDb(), tbl.getTbl(), + PrivPredicate.SHOW)) { + ErrorReport.reportAnalysisException(ErrorCode.ERR_TABLEACCESS_DENIED_ERROR, "SHOW CREATE MATERIALIZED", + ConnectContext.get().getQualifiedUser(), + ConnectContext.get().getRemoteIP(), + tbl.toSql()); + } + } + + public String getDbName() { + return dbName; + } + + public String getMvName() { + return mvName; + } + + public String getTableName() { + return tableName; + } + + public String getCatalog() { + return catalog; + } + + @Override + public void run(ConnectContext ctx, StmtExecutor executor) throws Exception { Review Comment: better to take the legacy planner's code as reference ``` private void handleShowCreateMaterializedView() throws AnalysisException { List<List<String>> resultRowSet = new ArrayList<>(); ShowCreateMaterializedViewStmt showStmt = (ShowCreateMaterializedViewStmt) stmt; Database db = Env.getCurrentInternalCatalog().getDbOrAnalysisException(showStmt.getTableName().getDb()); Table table = db.getTableOrAnalysisException(showStmt.getTableName().getTbl()); if (table instanceof OlapTable) { OlapTable baseTable = ((OlapTable) table); Long indexIdByName = baseTable.getIndexIdByName(showStmt.getMvName()); if (indexIdByName != null) { MaterializedIndexMeta meta = baseTable.getIndexMetaByIndexId(indexIdByName); if (meta != null && meta.getDefineStmt() != null) { String originStmt = meta.getDefineStmt().originStmt; List<String> data = new ArrayList<>(); data.add(showStmt.getTableName().getTbl()); data.add(showStmt.getMvName()); data.add(originStmt); resultRowSet.add(data); } } } resultSet = new ShowResultSet(showStmt.getMetaData(), resultRowSet); } ``` We just need some minor changes to migrate the old code to nereids, and it's more clear and easy to review. If rewrite the logical completely, it will take a lot more time to review the code and test it. And the pr may not be quickly merged until multiple round of test. So could you please re-implement these as legacy planner's logic -- 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