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

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

commit 9243b3eeeef03a4d29164472adcea2c832f54afa
Author: slothever <[email protected]>
AuthorDate: Wed Feb 28 21:22:33 2024 +0800

    [fix](multi-catalog) add config to disable external DDL (#31528)
    
    from #31453
---
 .../src/main/java/org/apache/doris/common/Config.java   |  6 ++++++
 .../java/org/apache/doris/analysis/CreateTableStmt.java |  4 ++++
 .../java/org/apache/doris/analysis/DropTableStmt.java   |  4 ++++
 .../src/main/java/org/apache/doris/catalog/Env.java     |  8 ++++++--
 .../org/apache/doris/datasource/ExternalCatalog.java    | 17 +++++++++++++++--
 5 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/fe/fe-common/src/main/java/org/apache/doris/common/Config.java 
b/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
index 4eb267e524f..45bf426984b 100644
--- a/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
+++ b/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
@@ -2216,6 +2216,12 @@ public class Config extends ConfigBase {
         "Sample size for hive row count estimation."})
     public static int hive_stats_partition_sample_size = 3000;
 
+    @ConfField(mutable = true, masterOnly = true, description = {
+            "启用外表DDL",
+            "Enable external table DDL"})
+    public static boolean enable_external_ddl = false;
+
+
     @ConfField(mutable = true, masterOnly = true, description = {
             "Hive创建外部表默认指定的input format",
             "Default hive input format for creating table."})
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java
index 6f43fab385c..bf0dc906fd9 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableStmt.java
@@ -254,6 +254,10 @@ public class CreateTableStmt extends DdlStmt {
         return engineName;
     }
 
+    public String getCatalogName() {
+        return tableName.getCtl();
+    }
+
     public String getDbName() {
         return tableName.getDb();
     }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/DropTableStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/DropTableStmt.java
index 70167d744da..ff679adc377 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DropTableStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DropTableStmt.java
@@ -61,6 +61,10 @@ public class DropTableStmt extends DdlStmt {
         return tableName.getTbl();
     }
 
+    public String getCatalogName() {
+        return tableName.getCtl();
+    }
+
     public boolean isView() {
         return isView;
     }
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 bbcb14207d4..effd7b6ca64 100755
--- 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
@@ -3039,7 +3039,9 @@ public class Env {
      * 11. add this table to ColocateGroup if necessary
      */
     public void createTable(CreateTableStmt stmt) throws UserException {
-        getCurrentCatalog().createTable(stmt);
+        CatalogIf<?> catalogIf = 
catalogMgr.getCatalogOrException(stmt.getCatalogName(),
+                catalog -> new DdlException(("Unknown catalog " + catalog)));
+        catalogIf.createTable(stmt);
     }
 
     public void createTableLike(CreateTableLikeStmt stmt) throws DdlException {
@@ -3659,7 +3661,9 @@ public class Env {
 
     // Drop table
     public void dropTable(DropTableStmt stmt) throws DdlException {
-        getCurrentCatalog().dropTable(stmt);
+        CatalogIf<?> catalogIf = 
catalogMgr.getCatalogOrException(stmt.getCatalogName(),
+                catalog -> new DdlException(("Unknown catalog " + catalog)));
+        catalogIf.dropTable(stmt);
     }
 
     public boolean unprotectDropTable(Database db, Table table, boolean 
isForceDrop, boolean isReplay,
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 0eabffce445..783f8a0fdfb 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
@@ -28,6 +28,7 @@ import org.apache.doris.catalog.InfoSchemaDb;
 import org.apache.doris.catalog.Resource;
 import org.apache.doris.catalog.TableIf;
 import org.apache.doris.cluster.ClusterNamespace;
+import org.apache.doris.common.Config;
 import org.apache.doris.common.DdlException;
 import org.apache.doris.common.UserException;
 import org.apache.doris.common.io.Text;
@@ -592,9 +593,12 @@ public abstract class ExternalCatalog
 
     @Override
     public void createDb(CreateDbStmt stmt) throws DdlException {
+        if (!Config.enable_external_ddl) {
+            throw new DdlException("Experimental. The config 
enable_external_ddl needs to be set to true.");
+        }
         makeSureInitialized();
         if (metadataOps == null) {
-            LOG.warn("dropDatabase not implemented");
+            LOG.warn("createDb not implemented");
             return;
         }
         try {
@@ -607,9 +611,12 @@ public abstract class ExternalCatalog
 
     @Override
     public void dropDb(DropDbStmt stmt) throws DdlException {
+        if (!Config.enable_external_ddl) {
+            throw new DdlException("Experimental. The config 
enable_external_ddl needs to be set to true.");
+        }
         makeSureInitialized();
         if (metadataOps == null) {
-            LOG.warn("dropDatabase not implemented");
+            LOG.warn("dropDb not implemented");
             return;
         }
         try {
@@ -622,6 +629,9 @@ public abstract class ExternalCatalog
 
     @Override
     public void createTable(CreateTableStmt stmt) throws UserException {
+        if (!Config.enable_external_ddl) {
+            throw new DdlException("Experimental. The config 
enable_external_ddl needs to be set to true.");
+        }
         makeSureInitialized();
         if (metadataOps == null) {
             LOG.warn("createTable not implemented");
@@ -637,6 +647,9 @@ public abstract class ExternalCatalog
 
     @Override
     public void dropTable(DropTableStmt stmt) throws DdlException {
+        if (!Config.enable_external_ddl) {
+            throw new DdlException("Experimental. The config 
enable_external_ddl needs to be set to true.");
+        }
         makeSureInitialized();
         if (metadataOps == null) {
             LOG.warn("dropTable not implemented");


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to