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

starocean999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new a44d19f835c [Enhancement] (nereids)implement DropTableCommand in 
nereids (#47594)
a44d19f835c is described below

commit a44d19f835c116a8f03d51c5573d5ab26cfe3267
Author: lsy3993 <110876560+lsy3...@users.noreply.github.com>
AuthorDate: Fri Feb 14 15:05:00 2025 +0800

    [Enhancement] (nereids)implement DropTableCommand in nereids (#47594)
    
    Issue Number: https://github.com/apache/doris/issues/42614
---
 .../antlr4/org/apache/doris/nereids/DorisParser.g4 |  4 +-
 .../java/org/apache/doris/analysis/TableName.java  | 20 +++++
 .../main/java/org/apache/doris/catalog/Env.java    | 13 +++-
 .../org/apache/doris/datasource/CatalogIf.java     |  3 +
 .../apache/doris/datasource/ExternalCatalog.java   | 14 +++-
 .../apache/doris/datasource/InternalCatalog.java   | 49 ++++++------
 .../doris/datasource/hive/HiveMetadataOps.java     | 16 ++--
 .../datasource/iceberg/IcebergMetadataOps.java     | 24 ++++--
 .../datasource/operations/ExternalMetadataOps.java |  7 ++
 .../doris/nereids/parser/LogicalPlanBuilder.java   | 27 +++++++
 .../apache/doris/nereids/trees/plans/PlanType.java |  1 +
 .../trees/plans/commands/DropTableCommand.java     | 87 ++++++++++++++++++++++
 .../trees/plans/commands/info/TableNameInfo.java   | 16 ++++
 .../trees/plans/visitor/CommandVisitor.java        |  5 ++
 .../suites/nereids_p0/drop/drop_table.groovy       | 37 +++++++++
 regression-test/suites/query_p0/dual/dual.groovy   |  8 +-
 16 files changed, 287 insertions(+), 44 deletions(-)

diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
index 2b914da48c9..6aaafe5ddb8 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
@@ -262,6 +262,7 @@ supportedDropStatement
         ((FROM | IN) database=identifier)? properties=propertyClause           
 #dropFile
     | DROP WORKLOAD POLICY (IF EXISTS)? name=identifierOrText                  
 #dropWorkloadPolicy
     | DROP REPOSITORY name=identifier                                          
 #dropRepository
+    | DROP TABLE (IF EXISTS)? name=multipartIdentifier FORCE?                  
 #dropTable
     | DROP (DATABASE | SCHEMA) (IF EXISTS)? name=multipartIdentifier FORCE?    
 #dropDatabase
     | DROP statementScope? FUNCTION (IF EXISTS)?
         functionIdentifier LEFT_PAREN functionArguments? RIGHT_PAREN           
 #dropFunction
@@ -718,8 +719,7 @@ fromRollup
     ;
 
 unsupportedDropStatement
-    : DROP TABLE (IF EXISTS)? name=multipartIdentifier FORCE?                  
 #dropTable
-    | DROP VIEW (IF EXISTS)? name=multipartIdentifier                          
 #dropView
+    : DROP VIEW (IF EXISTS)? name=multipartIdentifier                          
 #dropView
     | DROP RESOURCE (IF EXISTS)? name=identifierOrText                         
 #dropResource
     | DROP ROW POLICY (IF EXISTS)? policyName=identifier
         ON tableName=multipartIdentifier
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/TableName.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/TableName.java
index 81c96c9857d..612f445a60e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/TableName.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/TableName.java
@@ -29,6 +29,7 @@ import org.apache.doris.common.io.Text;
 import org.apache.doris.common.io.Writable;
 import org.apache.doris.datasource.InternalCatalog;
 import org.apache.doris.persist.gson.GsonUtils;
+import org.apache.doris.qe.ConnectContext;
 
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
@@ -95,6 +96,25 @@ public class TableName implements Writable {
         }
     }
 
+    public void analyze(ConnectContext ctx) {
+        if (Strings.isNullOrEmpty(ctl)) {
+            ctl = ctx.getDefaultCatalog();
+            if (Strings.isNullOrEmpty(ctl)) {
+                ctl = InternalCatalog.INTERNAL_CATALOG_NAME;
+            }
+        }
+        if (Strings.isNullOrEmpty(db)) {
+            db = ctx.getDatabase();
+            if (Strings.isNullOrEmpty(db)) {
+                throw new 
org.apache.doris.nereids.exceptions.AnalysisException("No database selected");
+            }
+        }
+
+        if (Strings.isNullOrEmpty(tbl)) {
+            throw new 
org.apache.doris.nereids.exceptions.AnalysisException("Table name is null");
+        }
+    }
+
     public String getCtl() {
         return ctl;
     }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
index bba7ca8b0c6..8fd97c21311 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
@@ -4232,9 +4232,18 @@ public class Env {
 
     // Drop table
     public void dropTable(DropTableStmt stmt) throws DdlException {
-        CatalogIf<?> catalogIf = 
catalogMgr.getCatalogOrException(stmt.getCatalogName(),
+        if (stmt == null) {
+            throw new DdlException("DropTableStmt is null");
+        }
+        dropTable(stmt.getCatalogName(), stmt.getDbName(), 
stmt.getTableName(), stmt.isView(),
+                stmt.isMaterializedView(), stmt.isSetIfExists(), 
stmt.isForceDrop());
+    }
+
+    public void dropTable(String catalogName, String dbName, String tableName, 
boolean isView, boolean isMtmv,
+                          boolean ifExists, boolean force) throws DdlException 
{
+        CatalogIf<?> catalogIf = catalogMgr.getCatalogOrException(catalogName,
                 catalog -> new DdlException(("Unknown catalog " + catalog)));
-        catalogIf.dropTable(stmt);
+        catalogIf.dropTable(dbName, tableName, isView, isMtmv, ifExists, 
force);
     }
 
     public boolean unprotectDropTable(Database db, Table table, boolean 
isForceDrop, boolean isReplay,
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogIf.java 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogIf.java
index c28e65c3478..9b8334c39a8 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogIf.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogIf.java
@@ -203,6 +203,9 @@ public interface CatalogIf<T extends DatabaseIf> {
 
     void dropTable(DropTableStmt stmt) throws DdlException;
 
+    void dropTable(String dbName, String tableName, boolean isView, boolean 
isMtmv, boolean ifExists,
+                   boolean force) throws DdlException;
+
     void truncateTable(TruncateTableStmt truncateTableStmt) throws 
DdlException;
 
     /**
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java
index 80adbfd67b6..9b1d26e3647 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/ExternalCatalog.java
@@ -1021,14 +1021,24 @@ public abstract class ExternalCatalog
 
     @Override
     public void dropTable(DropTableStmt stmt) throws DdlException {
+        if (stmt == null) {
+            throw new DdlException("DropTableStmt is null");
+        }
+        dropTable(stmt.getDbName(), stmt.getTableName(), stmt.isView(), 
stmt.isMaterializedView(), stmt.isSetIfExists(),
+                stmt.isForceDrop());
+    }
+
+    @Override
+    public void dropTable(String dbName, String tableName, boolean isView, 
boolean isMtmv, boolean ifExists,
+                          boolean force) throws DdlException {
         makeSureInitialized();
         if (metadataOps == null) {
             LOG.warn("dropTable not implemented");
             return;
         }
         try {
-            metadataOps.dropTable(stmt);
-            DropInfo info = new DropInfo(getName(), stmt.getDbName(), 
stmt.getTableName());
+            metadataOps.dropTable(dbName, tableName, ifExists);
+            DropInfo info = new DropInfo(getName(), dbName, tableName);
             Env.getCurrentEnv().getEditLog().logDropTable(info);
         } catch (Exception e) {
             LOG.warn("Failed to drop a table", e);
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
index 91b5e7f0f88..de8f4684572 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
@@ -877,11 +877,18 @@ public class InternalCatalog implements 
CatalogIf<Database> {
 
     // Drop table
     public void dropTable(DropTableStmt stmt) throws DdlException {
+        if (stmt == null) {
+            throw new DdlException("DropTableStmt is null");
+        }
+        dropTable(stmt.getDbName(), stmt.getTableName(), stmt.isView(), 
stmt.isMaterializedView(),
+                stmt.isSetIfExists(), stmt.isForceDrop());
+    }
+
+    public void dropTable(String dbName, String tableName, boolean isView, 
boolean isMtmv,
+                          boolean ifExists, boolean force) throws DdlException 
{
         Map<String, Long> costTimes = new TreeMap<String, Long>();
         StopWatch watch = StopWatch.createStarted();
-        String dbName = stmt.getDbName();
-        String tableName = stmt.getTableName();
-        LOG.info("begin to drop table: {} from db: {}, is force: {}", 
tableName, dbName, stmt.isForceDrop());
+        LOG.info("begin to drop table: {} from db: {}, is force: {}", 
tableName, dbName, force);
 
         // check database
         Database db = getDbOrDdlException(dbName);
@@ -895,7 +902,7 @@ public class InternalCatalog implements CatalogIf<Database> 
{
         try {
             Table table = db.getTableNullable(tableName);
             if (table == null) {
-                if (stmt.isSetIfExists()) {
+                if (ifExists) {
                     LOG.info("drop table[{}] which does not exist", tableName);
                     return;
                 } else {
@@ -903,7 +910,7 @@ public class InternalCatalog implements CatalogIf<Database> 
{
                 }
             }
             // Check if a view
-            if (stmt.isView()) {
+            if (isView) {
                 if (!(table instanceof View)) {
                     ErrorReport.reportDdlException(ErrorCode.ERR_WRONG_OBJECT, 
dbName, tableName, "VIEW",
                             genDropHint(dbName, table));
@@ -915,43 +922,43 @@ public class InternalCatalog implements 
CatalogIf<Database> {
                 }
             }
 
-            if (!stmt.isMaterializedView() && table instanceof MTMV) {
+            if (!isMtmv && table instanceof MTMV) {
                 ErrorReport.reportDdlException(ErrorCode.ERR_WRONG_OBJECT, 
dbName, tableName, "TABLE",
                         genDropHint(dbName, table));
-            } else if (stmt.isMaterializedView() && !(table instanceof MTMV)) {
+            } else if (isMtmv && !(table instanceof MTMV)) {
                 ErrorReport.reportDdlException(ErrorCode.ERR_WRONG_OBJECT, 
dbName, tableName, "MTMV",
                         genDropHint(dbName, table));
             }
 
-            if (!stmt.isForceDrop()) {
+            if (!force) {
                 if 
(Env.getCurrentGlobalTransactionMgr().existCommittedTxns(db.getId(), 
table.getId(), null)) {
                     throw new DdlException(
-                            "There are still some transactions in the 
COMMITTED state waiting to be completed. "
-                                    + "The table [" + tableName
-                                    + "] cannot be dropped. If you want to 
forcibly drop(cannot be recovered),"
-                                    + " please use \"DROP table FORCE\".");
+                        "There are still some transactions in the COMMITTED 
state waiting to be completed. "
+                            + "The table [" + tableName
+                            + "] cannot be dropped. If you want to forcibly 
drop(cannot be recovered),"
+                            + " please use \"DROP table FORCE\".");
                 }
                 watch.split();
                 costTimes.put("2:existCommittedTxns", watch.getSplitTime());
             }
 
-            if (table instanceof OlapTable && !stmt.isForceDrop()) {
+            if (table instanceof OlapTable && !force) {
                 OlapTable olapTable = (OlapTable) table;
                 if ((olapTable.getState() != OlapTableState.NORMAL)) {
                     throw new DdlException("The table [" + tableName + "]'s 
state is " + olapTable.getState()
-                            + ", cannot be dropped. please cancel the 
operation on olap table firstly."
-                            + " If you want to forcibly drop(cannot be 
recovered),"
-                            + " please use \"DROP table FORCE\".");
+                        + ", cannot be dropped. please cancel the operation on 
olap table firstly."
+                        + " If you want to forcibly drop(cannot be recovered),"
+                        + " please use \"DROP table FORCE\".");
                 }
                 if (olapTable.isInAtomicRestore()) {
                     throw new DdlException("The table [" + tableName + "]'s 
state is in atomic restore"
-                            + ", cannot be dropped. please cancel the restore 
operation on olap table"
-                            + " firstly. If you want to forcibly drop(cannot 
be recovered),"
-                            + " please use \"DROP table FORCE\".");
+                        + ", cannot be dropped. please cancel the restore 
operation on olap table"
+                        + " firstly. If you want to forcibly drop(cannot be 
recovered),"
+                        + " please use \"DROP table FORCE\".");
                 }
             }
 
-            dropTableInternal(db, table, stmt.isView(), stmt.isForceDrop(), 
watch, costTimes);
+            dropTableInternal(db, table, isView, force, watch, costTimes);
         } catch (UserException e) {
             throw new DdlException(e.getMessage(), e.getMysqlErrorCode());
         } finally {
@@ -960,7 +967,7 @@ public class InternalCatalog implements CatalogIf<Database> 
{
         watch.stop();
         costTimes.put("6:total", watch.getTime());
         LOG.info("finished dropping table: {} from db: {}, is view: {}, is 
force: {}, cost: {}",
-                tableName, dbName, stmt.isView(), stmt.isForceDrop(), 
costTimes);
+                tableName, dbName, isView, force, costTimes);
     }
 
     // drop table without any check.
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveMetadataOps.java
 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveMetadataOps.java
index 37005fa0eec..66a4162c853 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveMetadataOps.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveMetadataOps.java
@@ -287,11 +287,17 @@ public class HiveMetadataOps implements 
ExternalMetadataOps {
 
     @Override
     public void dropTableImpl(DropTableStmt stmt) throws DdlException {
-        String dbName = stmt.getDbName();
-        String tblName = stmt.getTableName();
-        ExternalDatabase<?> db = catalog.getDbNullable(stmt.getDbName());
+        if (stmt == null) {
+            throw new DdlException("DropTableStmt is null");
+        }
+        dropTableImpl(stmt.getDbName(), stmt.getTableName(), 
stmt.isSetIfExists());
+    }
+
+    @Override
+    public void dropTableImpl(String dbName, String tblName, boolean ifExists) 
throws DdlException {
+        ExternalDatabase<?> db = catalog.getDbNullable(dbName);
         if (db == null) {
-            if (stmt.isSetIfExists()) {
+            if (ifExists) {
                 LOG.info("database [{}] does not exist when drop table[{}]", 
dbName, tblName);
                 return;
             } else {
@@ -299,7 +305,7 @@ public class HiveMetadataOps implements ExternalMetadataOps 
{
             }
         }
         if (!tableExist(dbName, tblName)) {
-            if (stmt.isSetIfExists()) {
+            if (ifExists) {
                 LOG.info("drop table[{}] which does not exist", dbName);
                 return;
             } else {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergMetadataOps.java
 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergMetadataOps.java
index 0ee20690ea8..0159defbae0 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergMetadataOps.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergMetadataOps.java
@@ -250,14 +250,21 @@ public class IcebergMetadataOps implements 
ExternalMetadataOps {
 
     @Override
     public void dropTableImpl(DropTableStmt stmt) throws DdlException {
+        if (stmt == null) {
+            throw new DdlException("DropTableStmt is null");
+        }
+        dropTableImpl(stmt.getDbName(), stmt.getTableName(), 
stmt.isSetIfExists());
+    }
+
+    public void dropTableImpl(String dbName, String tableName, boolean 
ifExists) throws DdlException {
         try {
             preExecutionAuthenticator.execute(() -> {
-                performDropTable(stmt);
+                performDropTable(dbName, tableName, ifExists);
                 return null;
             });
         } catch (Exception e) {
             throw new DdlException(
-                "Failed to drop table: " + stmt.getTableName() + ", error 
message is:" + e.getMessage(), e);
+                "Failed to drop table: " + tableName + ", error message is:" + 
e.getMessage(), e);
         }
     }
 
@@ -270,11 +277,16 @@ public class IcebergMetadataOps implements 
ExternalMetadataOps {
     }
 
     private void performDropTable(DropTableStmt stmt) throws DdlException {
-        String dbName = stmt.getDbName();
-        String tableName = stmt.getTableName();
+        if (stmt == null) {
+            throw new DdlException("DropTableStmt is null");
+        }
+        performDropTable(stmt.getDbName(), stmt.getTableName(), 
stmt.isSetIfExists());
+    }
+
+    private void performDropTable(String dbName, String tableName, boolean 
ifExists) throws DdlException {
         ExternalDatabase<?> db = dorisCatalog.getDbNullable(dbName);
         if (db == null) {
-            if (stmt.isSetIfExists()) {
+            if (ifExists) {
                 LOG.info("database [{}] does not exist when drop table[{}]", 
dbName, tableName);
                 return;
             } else {
@@ -283,7 +295,7 @@ public class IcebergMetadataOps implements 
ExternalMetadataOps {
         }
 
         if (!tableExist(dbName, tableName)) {
-            if (stmt.isSetIfExists()) {
+            if (ifExists) {
                 LOG.info("drop table[{}] which does not exist", tableName);
                 return;
             } else {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/operations/ExternalMetadataOps.java
 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/operations/ExternalMetadataOps.java
index e8d6842ac44..d4055c65814 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/operations/ExternalMetadataOps.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/operations/ExternalMetadataOps.java
@@ -101,8 +101,15 @@ public interface ExternalMetadataOps {
         afterDropTable(stmt.getDbName(), stmt.getTableName());
     }
 
+    default void dropTable(String dbName, String tableName, boolean ifExists) 
throws DdlException {
+        dropTableImpl(dbName, tableName, ifExists);
+        afterDropTable(dbName, tableName);
+    }
+
     void dropTableImpl(DropTableStmt stmt) throws DdlException;
 
+    void dropTableImpl(String dbName, String tableName, boolean ifExists) 
throws DdlException;
+
     default void afterDropTable(String dbName, String tblName) {
     }
 
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index 9cc76395fa4..26b459b7c17 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -157,6 +157,7 @@ import org.apache.doris.nereids.DorisParser.DropRoleContext;
 import org.apache.doris.nereids.DorisParser.DropRollupClauseContext;
 import org.apache.doris.nereids.DorisParser.DropSqlBlockRuleContext;
 import org.apache.doris.nereids.DorisParser.DropStoragePolicyContext;
+import org.apache.doris.nereids.DorisParser.DropTableContext;
 import org.apache.doris.nereids.DorisParser.DropUserContext;
 import org.apache.doris.nereids.DorisParser.DropWorkloadGroupContext;
 import org.apache.doris.nereids.DorisParser.DropWorkloadPolicyContext;
@@ -560,6 +561,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.DropRepositoryCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropRoleCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropSqlBlockRuleCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropStoragePolicyCommand;
+import org.apache.doris.nereids.trees.plans.commands.DropTableCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropUserCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropWorkloadGroupCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropWorkloadPolicyCommand;
@@ -5371,6 +5373,31 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
         return new DropRoleCommand(ctx.name.getText(), ctx.EXISTS() != null);
     }
 
+    @Override
+    public LogicalPlan visitDropTable(DropTableContext ctx) {
+        String ctlName = null;
+        String dbName = null;
+        String tableName = null;
+        List<String> nameParts = visitMultipartIdentifier(ctx.name);
+        if (nameParts.size() == 1) {
+            tableName = nameParts.get(0);
+        } else if (nameParts.size() == 2) {
+            dbName = nameParts.get(0);
+            tableName = nameParts.get(1);
+        } else if (nameParts.size() == 3) {
+            ctlName = nameParts.get(0);
+            dbName = nameParts.get(1);
+            tableName = nameParts.get(2);
+        } else {
+            throw new AnalysisException("nameParts in create table should be 
[ctl.][db.]tbl");
+        }
+
+        boolean ifExists = ctx.EXISTS() != null;
+        boolean forceDrop = ctx.FORCE() != null;
+        TableNameInfo tblNameInfo = new TableNameInfo(ctlName, dbName, 
tableName);
+        return new DropTableCommand(ifExists, tblNameInfo, forceDrop);
+    }
+
     @Override
     public LogicalPlan visitDropCatalog(DropCatalogContext ctx) {
         String catalogName = stripQuotes(ctx.name.getText());
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
index 803c1bcbf57..395a4a87be7 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java
@@ -288,5 +288,6 @@ public enum PlanType {
     SWITCH_COMMAND,
     HELP_COMMAND,
     USE_COMMAND,
+    DROP_TABLE_COMMAND,
     ALTER_SYSTEM_RENAME_COMPUTE_GROUP
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropTableCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropTableCommand.java
new file mode 100644
index 00000000000..a8abc7b09cc
--- /dev/null
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropTableCommand.java
@@ -0,0 +1,87 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.plans.commands;
+
+import org.apache.doris.analysis.StmtType;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.util.InternalDatabaseUtil;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.nereids.trees.plans.commands.info.TableNameInfo;
+import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.StmtExecutor;
+
+import com.google.common.base.Strings;
+
+/**
+ * drop table command
+ */
+public class DropTableCommand extends Command implements ForwardWithSync {
+
+    private boolean ifExists;
+    private final TableNameInfo tableName;
+    private final boolean isView;
+    private boolean forceDrop;
+    private boolean isMaterializedView;
+
+    public DropTableCommand(boolean ifExists, TableNameInfo tableName, boolean 
forceDrop) {
+        super(PlanType.DROP_TABLE_COMMAND);
+        this.ifExists = ifExists;
+        this.tableName = tableName;
+        this.isView = false;
+        this.forceDrop = forceDrop;
+    }
+
+    public DropTableCommand(boolean ifExists, TableNameInfo tableName, boolean 
isView, boolean forceDrop) {
+        super(PlanType.DROP_TABLE_COMMAND);
+        this.ifExists = ifExists;
+        this.tableName = tableName;
+        this.isView = isView;
+        this.forceDrop = forceDrop;
+    }
+
+    @Override
+    public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+        return visitor.visitDropTableCommand(this, context);
+    }
+
+    @Override
+    public void run(ConnectContext ctx, StmtExecutor executor) throws 
Exception {
+        if (Strings.isNullOrEmpty(tableName.getDb())) {
+            tableName.setDb(ctx.getDatabase());
+        }
+        tableName.analyze(ctx);
+        InternalDatabaseUtil.checkDatabase(tableName.getDb(), ctx);
+        // check access
+        if (!Env.getCurrentEnv().getAccessManager()
+                .checkTblPriv(ConnectContext.get(), tableName.getCtl(), 
tableName.getDb(),
+                tableName.getTbl(), PrivPredicate.DROP)) {
+            
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, 
"DROP");
+        }
+        Env.getCurrentEnv().dropTable(tableName.getCtl(), tableName.getDb(), 
tableName.getTbl(), isView,
+                isMaterializedView, ifExists, forceDrop);
+    }
+
+    @Override
+    public StmtType stmtType() {
+        return StmtType.DROP;
+    }
+}
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/TableNameInfo.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/TableNameInfo.java
index a0bcc794b6b..1ddfec004dc 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/TableNameInfo.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/TableNameInfo.java
@@ -90,6 +90,22 @@ public class TableNameInfo implements Writable {
         this.db = db;
     }
 
+    /**
+     * TableNameInfo
+     * @param ctl catalogName
+     * @param db dbName
+     * @param tbl tblName
+     */
+    public TableNameInfo(String ctl, String db, String tbl) {
+        Objects.requireNonNull(tbl, "require tbl object");
+        this.ctl = ctl;
+        this.tbl = tbl;
+        if (Env.isStoredTableNamesLowerCase()) {
+            this.tbl = tbl.toLowerCase();
+        }
+        this.db = db;
+    }
+
     /**
      * analyze tableNameInfo
      * @param ctx ctx
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
index bdb6ce48826..4a241710041 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java
@@ -74,6 +74,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.DropRepositoryCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropRoleCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropSqlBlockRuleCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropStoragePolicyCommand;
+import org.apache.doris.nereids.trees.plans.commands.DropTableCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropUserCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropWorkloadGroupCommand;
 import org.apache.doris.nereids.trees.plans.commands.DropWorkloadPolicyCommand;
@@ -655,6 +656,10 @@ public interface CommandVisitor<R, C> {
         return visitCommand(createRoleCommand, context);
     }
 
+    default R visitDropTableCommand(DropTableCommand dropTableCommand, C 
context) {
+        return visitCommand(dropTableCommand, context);
+    }
+
     default R visitDropRoleCommand(DropRoleCommand dropRoleCommand, C context) 
{
         return visitCommand(dropRoleCommand, context);
     }
diff --git a/regression-test/suites/nereids_p0/drop/drop_table.groovy 
b/regression-test/suites/nereids_p0/drop/drop_table.groovy
new file mode 100644
index 00000000000..c35971a4d7b
--- /dev/null
+++ b/regression-test/suites/nereids_p0/drop/drop_table.groovy
@@ -0,0 +1,37 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_nereids_drop_table") {
+    def table_name = "nereids_test_drop_table"
+    def db_name = "nereids_test_db_name"
+
+    sql """DROP DATABASE IF EXISTS ${db_name}"""
+
+    sql """CREATE DATABASE ${db_name}"""
+
+    sql """  
+      CREATE TABLE IF NOT EXISTS ${table_name}
+      (
+      `user_id` LARGEINT NOT NULL COMMENT "用户id"
+      ) ENGINE = olap
+      DUPLICATE KEY(`user_id`)
+      DISTRIBUTED BY HASH(`user_id`) BUCKETS 2
+      PROPERTIES ("replication_num" = "1");
+    """
+    checkNereidsExecute("DROP TABLE ${table_name}")
+
+}
diff --git a/regression-test/suites/query_p0/dual/dual.groovy 
b/regression-test/suites/query_p0/dual/dual.groovy
index 964ca49f3ab..868fdce895b 100644
--- a/regression-test/suites/query_p0/dual/dual.groovy
+++ b/regression-test/suites/query_p0/dual/dual.groovy
@@ -60,11 +60,7 @@ suite('dual') {
     qt_sql 'select 1 from `dual`'
     qt_sql 'select 1 from dual'
 
-    // Tests for dropping 'dual' and ensuring correct error handling
-    test {
-        sql 'drop table if exists dual'
-        exception """DUAL is keyword, maybe `DUAL`"""
-    }
+    sql 'drop table if exists dual'
     sql 'drop table if exists `dual`'
 
     // Test error handling when table does not exist
@@ -82,4 +78,4 @@ suite('dual') {
         sql "select 1, a from dual"
         exception "Unknown column 'a' in 'table list'"
     }
-}
\ No newline at end of file
+}


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

Reply via email to