weizhengte commented on code in PR #8858: URL: https://github.com/apache/incubator-doris/pull/8858#discussion_r852545730
########## fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyzeStmt.java: ########## @@ -17,19 +17,181 @@ package org.apache.doris.analysis; +import org.apache.doris.catalog.Catalog; +import org.apache.doris.catalog.Column; +import org.apache.doris.catalog.Database; +import org.apache.doris.catalog.Table; +import org.apache.doris.cluster.ClusterNamespace; +import org.apache.doris.common.AnalysisException; +import org.apache.doris.common.Config; +import org.apache.doris.common.ErrorCode; +import org.apache.doris.common.ErrorReport; +import org.apache.doris.common.UserException; +import org.apache.doris.mysql.privilege.PaloAuth; +import org.apache.doris.mysql.privilege.PrivPredicate; +import org.apache.doris.qe.ConnectContext; + +import com.clearspring.analytics.util.Lists; +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; +import com.google.common.collect.Maps; + +import org.apache.commons.lang3.StringUtils; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + /** * Collect statistics about a database - * + * <p> * syntax: * ANALYZE [[ db_name.tb_name ] [( column_name [, ...] )], ...] [ PROPERTIES(...) ] - * - * db_name.tb_name: collect table and column statistics from tb_name - * - * column_name: collect column statistics from column_name - * - * properties: properties of statistics jobs - * + * <p> + * db_name.tb_name: collect table and column statistics from tb_name + * <p> + * column_name: collect column statistics from column_name + * <p> + * properties: properties of statistics jobs */ public class AnalyzeStmt extends DdlStmt { + private final TableName dbTableName; + private final List<String> columnNames; + private Map<String, String> properties; + + // after analyzed + private Database db; + private List<Table> tables; + private final Map<Long, List<String>> tableIdToColumnName = Maps.newHashMap(); + + public AnalyzeStmt(TableName dbTableName, List<String> columns, Map<String, String> properties) { + this.dbTableName = dbTableName; + this.columnNames = columns; + this.properties = properties; + } + + public Database getDb() { + Preconditions.checkArgument(isAnalyzed(), + "The db name must be obtained after the parsing is complete"); + return this.db; + } + + public List<Table> getTables() { + Preconditions.checkArgument(isAnalyzed(), + "The db name must be obtained after the parsing is complete"); + return this.tables; + } + + public Map<Long, List<String>> getTableIdToColumnName() { + Preconditions.checkArgument(isAnalyzed(), + "The db name must be obtained after the parsing is complete"); + return this.tableIdToColumnName; + } + + public Map<String, String> getProperties() { + return this.properties; + } + @Override + public void analyze(Analyzer analyzer) throws UserException { + super.analyze(analyzer); + + // step1: analyze database and table + if (this.dbTableName != null) { + String dbName; + if (Strings.isNullOrEmpty(this.dbTableName.getDb())) { + dbName = analyzer.getDefaultDb(); + } else { + dbName = ClusterNamespace.getFullName(analyzer.getClusterName(), this.dbTableName.getDb()); + } + + // check db + if (Strings.isNullOrEmpty(dbName)) { Review Comment: got it. -- 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