This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 296bfb3350f696adc719eadb71384dcafd98ed8d
Author: Xiangyu Wang <dut.xian...@gmail.com>
AuthorDate: Wed Jul 5 16:28:05 2023 +0800

    [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
---
 .../org/apache/doris/analysis/ShowPartitionsStmt.java   | 17 ++++++++++++++---
 .../main/java/org/apache/doris/catalog/DatabaseIf.java  |  4 ++--
 .../src/main/java/org/apache/doris/qe/ShowExecutor.java |  5 ++---
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowPartitionsStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowPartitionsStmt.java
index d7de6ee560..f6e9b06e0b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowPartitionsStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowPartitionsStmt.java
@@ -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
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/DatabaseIf.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/DatabaseIf.java
index 4c696b9ef9..7672b8b76d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/DatabaseIf.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/DatabaseIf.java
@@ -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;
     }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
index 06aa997695..7f5d197723 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
@@ -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);
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to