diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowDataSkewStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowDataSkewStmt.java index 6463960241ab46..a1806278358010 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowDataSkewStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowDataSkewStmt.java @@ -18,11 +18,8 @@ package org.apache.doris.analysis; import org.apache.doris.catalog.Column; -import org.apache.doris.catalog.DatabaseIf; import org.apache.doris.catalog.Env; 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.UserException; @@ -33,9 +30,6 @@ import com.google.common.collect.ImmutableList; -import java.util.ArrayList; -import java.util.Optional; - // show data skew from tbl [partition(p1, p2, ...)] public class ShowDataSkewStmt extends ShowStmt { public static final ImmutableList TITLE_NAMES = new ImmutableList.Builder() @@ -63,24 +57,6 @@ public void analyze(Analyzer analyzer) throws UserException { ConnectContext.get().getRemoteIP(), tblRef.getName().getDb() + "." + tblRef.getName().getTbl()); } - - Optional db = Env.getCurrentEnv().getCurrentCatalog().getDb(tblRef.getName().getDb()); - if (!db.isPresent()) { - throw new AnalysisException("Can not find db: " + tblRef.getName().getDb()); - } - Optional tbl = db.get().getTable(tblRef.getName().getTbl()); - if (!tbl.isPresent()) { - throw new AnalysisException("Can not find table: " + tblRef.getName().getDb() + "." - + tblRef.getName().getTbl()); - } - - PartitionNames partitionNames = tblRef.getPartitionNames(); - if (partitionNames == null) { - if (tbl.get().getPartitionNames().isEmpty()) { - throw new AnalysisException("Can not find any partition"); - } - tblRef.setPartitionNames(new PartitionNames(false, new ArrayList<>(tbl.get().getPartitionNames()))); - } } public String getDbName() { diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/MetadataViewer.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/MetadataViewer.java index 38a8a245b5ee44..333b7b146acf27 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/MetadataViewer.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/MetadataViewer.java @@ -34,6 +34,7 @@ import java.text.DecimalFormat; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -267,19 +268,34 @@ private static List> getDataSkew(String dbName, String tblName, Par List> result = Lists.newArrayList(); Env env = Env.getCurrentEnv(); - if (partitionNames == null) { - throw new DdlException("Can not find any partition"); - } - Database db = env.getInternalCatalog().getDbOrDdlException(dbName); OlapTable olapTable = db.getOlapTableOrDdlException(tblName); + if (olapTable.getPartitionNames().isEmpty()) { + throw new DdlException("Can not find any partition from " + dbName + "." + tblName); + } + + // patition -> isTmep + Map allPartionNames = new HashMap<>(); + if (partitionNames == null) { + for (Partition p : olapTable.getPartitions()) { + allPartionNames.put(p.getName(), false); + } + for (Partition p : olapTable.getTempPartitions()) { + allPartionNames.put(p.getName(), true); + } + } else { + for (String name : partitionNames.getPartitionNames()) { + allPartionNames.put(name, partitionNames.isTemp()); + } + } + olapTable.readLock(); try { Partition partition = null; // check partition - for (String partName : partitionNames.getPartitionNames()) { - partition = olapTable.getPartition(partName, partitionNames.isTemp()); + for (Map.Entry partName : allPartionNames.entrySet()) { + partition = olapTable.getPartition(partName.getKey(), partName.getValue()); if (partition == null) { throw new DdlException("Partition does not exist: " + partName); } @@ -307,7 +323,7 @@ private static List> getDataSkew(String dbName, String tblName, Par // graph for (int i = 0; i < distributionInfo.getBucketNum(); i++) { List row = Lists.newArrayList(); - row.add(partName); + row.add(partName.getKey()); row.add(String.valueOf(i)); row.add(rowCountTabletInfos.get(i).toString()); row.add(dataSizeTabletInfos.get(i).toString());