Skip to content

Commit

Permalink
add normal and temp partitions
Browse files Browse the repository at this point in the history
  • Loading branch information
xiedeyantu committed Mar 26, 2024
1 parent 3fe6fe4 commit 0e3d052
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> TITLE_NAMES = new ImmutableList.Builder<String>()
Expand Down Expand Up @@ -63,24 +57,6 @@ public void analyze(Analyzer analyzer) throws UserException {
ConnectContext.get().getRemoteIP(),
tblRef.getName().getDb() + "." + tblRef.getName().getTbl());
}

Optional<DatabaseIf> db = Env.getCurrentEnv().getCurrentCatalog().getDb(tblRef.getName().getDb());
if (!db.isPresent()) {
throw new AnalysisException("Can not find db: " + tblRef.getName().getDb());
}
Optional<TableIf> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import java.text.DecimalFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -267,19 +268,34 @@ private static List<List<String>> getDataSkew(String dbName, String tblName, Par
List<List<String>> 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<String, Boolean> 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<String, Boolean> partName : allPartionNames.entrySet()) {
partition = olapTable.getPartition(partName.getKey(), partName.getValue());
if (partition == null) {
throw new DdlException("Partition does not exist: " + partName);
}
Expand Down Expand Up @@ -307,7 +323,7 @@ private static List<List<String>> getDataSkew(String dbName, String tblName, Par
// graph
for (int i = 0; i < distributionInfo.getBucketNum(); i++) {
List<String> 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());
Expand Down

0 comments on commit 0e3d052

Please sign in to comment.