starocean999 commented on code in PR #47591: URL: https://github.com/apache/doris/pull/47591#discussion_r1984357754
########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowQueryStatsCommand.java: ########## @@ -0,0 +1,165 @@ +// 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.catalog.Column; +import org.apache.doris.catalog.Env; +import org.apache.doris.catalog.ScalarType; +import org.apache.doris.common.ErrorCode; +import org.apache.doris.common.ErrorReport; +import org.apache.doris.common.Pair; +import org.apache.doris.mysql.privilege.PrivPredicate; +import org.apache.doris.nereids.trees.plans.PlanType; +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 org.apache.doris.statistics.query.QueryStatsUtil; + +import com.google.common.collect.Lists; + +import java.util.List; +import java.util.Map; + +/** + * show query stats command + */ +public class ShowQueryStatsCommand extends ShowCommand { + private static final ShowResultSetMetaData SHOW_QUERY_STATS_CATALOG_META_DATA = ShowResultSetMetaData.builder() + .addColumn(new Column("Database", ScalarType.createVarchar(20))) + .addColumn(new Column("QueryCount", ScalarType.createVarchar(30))).build(); + private static final ShowResultSetMetaData SHOW_QUERY_STATS_DATABASE_META_DATA = ShowResultSetMetaData.builder() + .addColumn(new Column("TableName", ScalarType.createVarchar(20))) + .addColumn(new Column("QueryCount", ScalarType.createVarchar(30))).build(); + private static final ShowResultSetMetaData SHOW_QUERY_STATS_TABLE_META_DATA = ShowResultSetMetaData.builder() + .addColumn(new Column("Field", ScalarType.createVarchar(20))) + .addColumn(new Column("QueryCount", ScalarType.createVarchar(30))) + .addColumn(new Column("FilterCount", ScalarType.createVarchar(30))).build(); + private static final ShowResultSetMetaData SHOW_QUERY_STATS_TABLE_ALL_META_DATA = ShowResultSetMetaData.builder() + .addColumn(new Column("IndexName", ScalarType.createVarchar(20))) + .addColumn(new Column("QueryCount", ScalarType.createVarchar(30))).build(); + private static final ShowResultSetMetaData SHOW_QUERY_STATS_TABLE_ALL_VERBOSE_META_DATA + = ShowResultSetMetaData.builder().addColumn(new Column("IndexName", ScalarType.createVarchar(20))) + .addColumn(new Column("Field", ScalarType.createVarchar(20))) + .addColumn(new Column("QueryCount", ScalarType.createVarchar(30))) + .addColumn(new Column("FilterCount", ScalarType.createVarchar(30))).build(); + + private final String database; + private final String table; + private final boolean isAll; + private final boolean isVerbose; + + /** + * Constructor + */ + public ShowQueryStatsCommand(String database, String table, boolean isAll, boolean isVerbose) { + super(PlanType.SHOW_QUERY_STATS_COMMAND); + this.database = database; + this.table = table; + this.isAll = isAll; + this.isVerbose = isVerbose; + } + + @Override + public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { + String catalog = ctx.getCurrentCatalog().getName(); Review Comment: please check the ShowQueryStatsStmt.analyze() method, there are some code missing like bellow: ``` if (tableName != null) { tableName.analyze(analyzer); dbName = tableName.getDb(); } Database db = (Database) Env.getCurrentEnv().getCurrentCatalog().getDbOrDdlException(dbName); String ctlName = db.getCatalog().getName(); if (tableName != null) { db.getTableOrDdlException(tableName.getTbl()); } ``` you can create a `void validate(ConnectContext ctx)`method to wrap all validation code to do exact same thing as old analyze() method. and just call validate(ctx) here -- 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