[Enhancement](multi-catalog) Add some checks for ShowPartitionsStmt. (#21446)

1.  Add some validations for ShowPartitionsStmt with hive tables
2. Make the behavior consistently with hive
This commit is contained in:
Xiangyu Wang
2023-07-05 16:28:05 +08:00
committed by GitHub
parent 0da1bc7acd
commit f868aa9d4a
3 changed files with 18 additions and 8 deletions

View File

@ -25,6 +25,7 @@ import org.apache.doris.catalog.Table;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.TableIf.TableType;
import org.apache.doris.catalog.Type;
import org.apache.doris.catalog.external.HMSExternalTable;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
@ -41,6 +42,7 @@ import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.ShowResultSetMetaData;
import com.google.common.base.Strings;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -121,12 +123,21 @@ public class ShowPartitionsStmt extends ShowStmt {
ConnectContext.get().getRemoteIP(),
dbName + ": " + tblName);
}
if (!catalog.isInternalCatalog()) {
DatabaseIf db = catalog.getDbOrAnalysisException(dbName);
TableIf table = db.getTableOrMetaException(tblName, Table.TableType.OLAP, TableType.MATERIALIZED_VIEW,
TableType.HMS_EXTERNAL_TABLE);
if (table instanceof HMSExternalTable) {
if (((HMSExternalTable) table).isView()) {
throw new AnalysisException("Table " + tblName + " is not a partitioned table");
}
if (CollectionUtils.isEmpty(((HMSExternalTable) table).getPartitionColumns())) {
throw new AnalysisException("Table " + tblName + " is not a partitioned table");
}
return;
}
DatabaseIf db = catalog.getDbOrAnalysisException(dbName);
TableIf table = db.getTableOrMetaException(tblName, Table.TableType.OLAP, TableType.MATERIALIZED_VIEW);
table.readLock();
try {
// build proc path

View File

@ -169,7 +169,7 @@ public interface DatabaseIf<T extends TableIf> {
T table = getTableOrMetaException(tableName);
if (!tableTypes.contains(table.getType())) {
throw new MetaNotFoundException(
"Tye type of " + tableName + " doesn't match, expected data tables=" + tableTypes);
"Type of " + tableName + " doesn't match, expected data tables=" + tableTypes);
}
return table;
}
@ -193,7 +193,7 @@ public interface DatabaseIf<T extends TableIf> {
T table = getTableOrMetaException(tableId);
if (!tableTypes.contains(table.getType())) {
throw new MetaNotFoundException(
"Tye type of " + tableId + " doesn't match, expected data tables=" + tableTypes);
"Type of " + tableId + " doesn't match, expected data tables=" + tableTypes);
}
return table;
}

View File

@ -1583,6 +1583,7 @@ public class ShowExecutor {
HMSExternalCatalog catalog = (HMSExternalCatalog) (showStmt.getCatalog());
List<List<String>> rows = new ArrayList<>();
String dbName = ClusterNamespace.getNameFromFullName(showStmt.getTableName().getDb());
List<String> partitionNames = catalog.getClient().listPartitionNames(dbName,
showStmt.getTableName().getTbl());
for (String partition : partitionNames) {
@ -1592,9 +1593,7 @@ public class ShowExecutor {
}
// sort by partition name
rows.sort((x, y) -> {
return x.get(0).compareTo(y.get(0));
});
rows.sort(Comparator.comparing(x -> x.get(0)));
resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
}