Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xiedeyantu committed Feb 20, 2025
1 parent 0f306f9 commit c2d4afa
Show file tree
Hide file tree
Showing 8 changed files with 281 additions and 459 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,6 @@
import org.apache.doris.nereids.trees.plans.commands.info.AlterSystemOp;
import org.apache.doris.nereids.trees.plans.commands.info.AlterTableOp;
import org.apache.doris.nereids.trees.plans.commands.info.AlterViewInfo;
import org.apache.doris.nereids.trees.plans.commands.info.AnalyzeDatabaseOp;
import org.apache.doris.nereids.trees.plans.commands.info.AnalyzeTableOp;
import org.apache.doris.nereids.trees.plans.commands.info.BuildIndexOp;
import org.apache.doris.nereids.trees.plans.commands.info.BulkLoadDataDesc;
import org.apache.doris.nereids.trees.plans.commands.info.BulkStorageDesc;
Expand Down Expand Up @@ -5846,9 +5844,8 @@ public LogicalPlan visitAnalyzeTable(DorisParser.AnalyzeTableContext ctx) {
}
propertiesMap.putAll(visitPropertyClause(ctx.propertyClause()));
AnalyzeProperties properties = new AnalyzeProperties(propertiesMap);
AnalyzeTableOp analyzeTableOp = new AnalyzeTableOp(tableNameInfo,
return new AnalyzeTableCommand(tableNameInfo,
partitionNamesInfo, columnNames, properties);
return new AnalyzeTableCommand(analyzeTableOp);
}

@Override
Expand All @@ -5875,8 +5872,7 @@ public LogicalPlan visitAnalyzeDatabase(DorisParser.AnalyzeDatabaseContext ctx)
}
propertiesMap.putAll(visitPropertyClause(ctx.propertyClause()));
AnalyzeProperties properties = new AnalyzeProperties(propertiesMap);
AnalyzeDatabaseOp analyzeDatabaseOp = new AnalyzeDatabaseOp(ctlName, dbName, properties);
return new AnalyzeDatabaseCommand(analyzeDatabaseOp);
return new AnalyzeDatabaseCommand(ctlName, dbName, properties);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@
package org.apache.doris.nereids.trees.plans.commands;

import org.apache.doris.analysis.AnalyzeProperties;
import org.apache.doris.analysis.RedirectStatus;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.UserException;
import org.apache.doris.nereids.trees.plans.PlanType;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.StmtExecutor;
import org.apache.doris.statistics.AnalysisInfo;
import org.apache.doris.statistics.util.StatisticsUtil;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.util.CronExpression;

import java.util.Map;

/**
* AnalyzeCommand
Expand All @@ -35,6 +41,8 @@ public abstract class AnalyzeCommand extends Command implements ForwardWithSync

protected AnalyzeProperties analyzeProperties;

protected PlanType planType;

/**
* AnalyzeCommand
*/
Expand Down Expand Up @@ -66,4 +74,74 @@ public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {

public abstract void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception;

public Map<String, String> getProperties() {
return analyzeProperties.getProperties();
}

public AnalysisInfo.AnalysisType getAnalysisType() {
return analyzeProperties.getAnalysisType();
}

public AnalysisInfo.AnalysisMethod getAnalysisMethod() {
double samplePercent = analyzeProperties.getSamplePercent();
int sampleRows = analyzeProperties.getSampleRows();
return (samplePercent > 0 || sampleRows > 0)
? AnalysisInfo.AnalysisMethod.SAMPLE
: AnalysisInfo.AnalysisMethod.FULL;
}

public AnalysisInfo.ScheduleType getScheduleType() {
if (analyzeProperties.isAutomatic()) {
return AnalysisInfo.ScheduleType.AUTOMATIC;
}
return analyzeProperties.getPeriodTimeInMs() > 0 || analyzeProperties.getCron() != null
? AnalysisInfo.ScheduleType.PERIOD : AnalysisInfo.ScheduleType.ONCE;
}

public boolean isSync() {
return analyzeProperties.isSync();
}

public int getSamplePercent() {
return analyzeProperties.getSamplePercent();
}

public int getSampleRows() {
return analyzeProperties.getSampleRows();
}

public int getNumBuckets() {
return analyzeProperties.getNumBuckets();
}

public long getPeriodTimeInMs() {
return analyzeProperties.getPeriodTimeInMs();
}

public AnalyzeProperties getAnalyzeProperties() {
return analyzeProperties;
}

public RedirectStatus getRedirectStatus() {
return RedirectStatus.FORWARD_WITH_SYNC;
}

public CronExpression getCron() {
return analyzeProperties.getCron();
}

public boolean forceFull() {
return analyzeProperties.forceFull();
}

public boolean usingSqlForExternalTable() {
return analyzeProperties.usingSqlForExternalTable();
}

public void validate(ConnectContext ctx) throws UserException {
if (analyzeProperties != null) {
analyzeProperties.check();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@

package org.apache.doris.nereids.trees.plans.commands;

import org.apache.doris.analysis.AnalyzeProperties;
import org.apache.doris.catalog.DatabaseIf;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.common.UserException;
import org.apache.doris.datasource.CatalogIf;
import org.apache.doris.nereids.trees.plans.PlanType;
import org.apache.doris.nereids.trees.plans.commands.info.AnalyzeDatabaseOp;
import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.StmtExecutor;
Expand All @@ -27,23 +32,40 @@
* AnalyzeDatabaseCommand
*/
public class AnalyzeDatabaseCommand extends AnalyzeCommand {
AnalyzeDatabaseOp analyzeDatabaseOp;
private final String ctlName;
private final String dbName;

private CatalogIf ctlIf;

private DatabaseIf<TableIf> db;

/**
* AnalyzeCommand
*/
public AnalyzeDatabaseCommand(AnalyzeDatabaseOp analyzeDatabaseOp) {
super(PlanType.ANALYZE_DATABASE, analyzeDatabaseOp.getAnalyzeProperties());
this.analyzeDatabaseOp = analyzeDatabaseOp;
public AnalyzeDatabaseCommand(String ctlName, String dbName, AnalyzeProperties properties) {
super(PlanType.ANALYZE_DATABASE, properties);
this.ctlName = ctlName;
this.dbName = dbName;
}

@Override
public void validate(ConnectContext ctx) throws UserException {
super.validate(ctx);
if (ctlName == null) {
ctlIf = Env.getCurrentEnv().getCurrentCatalog();
} else {
ctlIf = Env.getCurrentEnv().getCatalogMgr().getCatalogOrAnalysisException(ctlName);
}
db = ctlIf.getDbOrAnalysisException(dbName);
}

public AnalyzeDatabaseOp getAnalyzeDatabaseOp() {
return analyzeDatabaseOp;
public DatabaseIf<TableIf> getDb() {
return db;
}

@Override
public void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception {
analyzeDatabaseOp.validate(ctx);
validate(ctx);
ctx.getEnv().analyze(this, executor.isProxy());
}

Expand Down
Loading

0 comments on commit c2d4afa

Please sign in to comment.