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

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


The following commit(s) were added to refs/heads/branch-3.1 by this push:
     new 4849a9b5d32 branch-3.1:[feature](schema) support temporary table in 
old planner (#53355)
4849a9b5d32 is described below

commit 4849a9b5d32e779dc939d236a20fab8d50f56c03
Author: zhangdong <[email protected]>
AuthorDate: Mon Jul 28 10:33:29 2025 +0800

    branch-3.1:[feature](schema) support temporary table in old planner (#53355)
    
    ### What problem does this PR solve?
    
    Related PR: #40680
    
    In #40680, some logic was
    implemented in the new optimizer, but the new optimizer's implementation
    was not picked for version 3.1. Therefore, this PR reimplements part of
    the logic in the old optimizer.
    
    The following classes have already been picked for 3.1 and do not need
    modification:
    - 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableLikeInfo.java
    - 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableInfo.java
    - 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java
    - 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ExportCommand.java
    
    The following classes were not picked for 3.1, but similar logic has
    already been implemented at the execution layer, so no changes are
    needed.
    - 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowAnalyzeCommand.java
    - 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCreateTableCommand.java
    - 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowDataCommand.java
    - 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowDynamicPartitionCommand.java
    - 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowPartitionIdCommand.java
    - 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowTableIdCommand.java
    
    The following classes need to be modified in the old optimizer:
    - 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterTableCommand.java
    - 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateMaterializedViewCommand.java
    - 
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowTableCommand.java
---
 .../org/apache/doris/analysis/AlterTableStmt.java  | 20 +++++++++++
 .../doris/analysis/CreateMaterializedViewStmt.java |  3 ++
 .../java/org/apache/doris/qe/ShowExecutor.java     |  3 ++
 .../apache/doris/analysis/AlterTableStmtTest.java  | 42 ++++++++++++++++++++++
 4 files changed, 68 insertions(+)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStmt.java
index 36db1e3d863..d6be805b674 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStmt.java
@@ -19,13 +19,16 @@ package org.apache.doris.analysis;
 
 import org.apache.doris.catalog.AggregateType;
 import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.DatabaseIf;
 import org.apache.doris.catalog.Env;
 import org.apache.doris.catalog.KeysType;
 import org.apache.doris.catalog.MaterializedIndex;
 import org.apache.doris.catalog.OlapTable;
 import org.apache.doris.catalog.Table;
+import org.apache.doris.catalog.TableIf;
 import org.apache.doris.catalog.Type;
 import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.DdlException;
 import org.apache.doris.common.ErrorCode;
 import org.apache.doris.common.ErrorReport;
 import org.apache.doris.common.UserException;
@@ -34,6 +37,8 @@ import org.apache.doris.common.util.PropertyAnalyzer;
 import org.apache.doris.mysql.privilege.PrivPredicate;
 import org.apache.doris.qe.ConnectContext;
 
+import com.google.common.annotations.VisibleForTesting;
+
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -88,6 +93,21 @@ public class AlterTableStmt extends DdlStmt implements 
NotFallbackInParser {
             }
             op.analyze(analyzer);
         }
+        checkTemporaryTable();
+    }
+
+    @VisibleForTesting
+    public void checkTemporaryTable() throws DdlException, AnalysisException {
+        String ctlName = tbl.getCtl();
+        String dbName = tbl.getDb();
+        String tableName = tbl.getTbl();
+        DatabaseIf dbIf = Env.getCurrentEnv().getCatalogMgr()
+                .getCatalogOrException(ctlName, catalog -> new 
DdlException("Unknown catalog " + catalog))
+                .getDbOrDdlException(dbName);
+        TableIf tableIf = dbIf.getTableOrDdlException(tableName);
+        if (tableIf.isTemporary()) {
+            throw new AnalysisException("Do not support alter temporary 
table[" + tableName + "]");
+        }
     }
 
     public void rewriteAlterClause(OlapTable table) throws UserException {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
index e1404e251fc..bc1364a7d68 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
@@ -331,6 +331,9 @@ public class CreateMaterializedViewStmt extends DdlStmt 
implements NotFallbackIn
             throw new AnalysisException("The materialized view only support 
olap table.");
         }
         OlapTable olapTable = (OlapTable) tableRefList.get(0).getTable();
+        if (olapTable.isTemporary()) {
+            throw new AnalysisException("do not support create materialized 
view on temporary table");
+        }
         mvKeysType = olapTable.getKeysType();
 
         TableName tableName = tableRefList.get(0).getName();
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 a16c4584f85..d20aac3b270 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
@@ -1030,6 +1030,9 @@ public class ShowExecutor {
             if (matcher != null && !matcher.match(tbl.getName())) {
                 continue;
             }
+            if (tbl.isTemporary()) {
+                continue;
+            }
             // check tbl privs
             if (!Env.getCurrentEnv().getAccessManager()
                     .checkTblPriv(ConnectContext.get(), 
showTableStmt.getCatalog(), db.getFullName(), tbl.getName(),
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/analysis/AlterTableStmtTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/analysis/AlterTableStmtTest.java
index 61192f202d9..9467e068501 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/AlterTableStmtTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/AlterTableStmtTest.java
@@ -70,6 +70,12 @@ public class AlterTableStmtTest {
         ops.add(new DropColumnClause("col1", "", null));
         ops.add(new DropColumnClause("col2", "", null));
         AlterTableStmt stmt = new AlterTableStmt(new TableName(internalCtl, 
"testDb", "testTbl"), ops);
+        new Expectations() {
+            {
+                stmt.checkTemporaryTable();
+                minTimes = 0;
+            }
+        };
         stmt.analyze(analyzer);
         Assert.assertEquals("ALTER TABLE `testDb`.`testTbl` DROP COLUMN 
`col1`, \nDROP COLUMN `col2`",
                 stmt.toSql());
@@ -83,6 +89,12 @@ public class AlterTableStmtTest {
         ops.add(new AddRollupClause("index1", Lists.newArrayList("col1", 
"col2"), null, "testTbl", null));
         ops.add(new AddRollupClause("index2", Lists.newArrayList("col2", 
"col3"), null, "testTbl", null));
         AlterTableStmt stmt = new AlterTableStmt(new TableName(internalCtl, 
"testDb", "testTbl"), ops);
+        new Expectations() {
+            {
+                stmt.checkTemporaryTable();
+                minTimes = 0;
+            }
+        };
         stmt.analyze(analyzer);
         Assert.assertEquals("ALTER TABLE `testDb`.`testTbl`"
                         + " ADD ROLLUP `index1` (`col1`, `col2`) FROM 
`testTbl`, \n"
@@ -118,6 +130,12 @@ public class AlterTableStmtTest {
         properties.put("function_column.sequence_type", "int");
         ops.add(new EnableFeatureClause("sequence_load", properties));
         AlterTableStmt stmt = new AlterTableStmt(new TableName(internalCtl, 
"testDb", "testTbl"), ops);
+        new Expectations() {
+            {
+                stmt.checkTemporaryTable();
+                minTimes = 0;
+            }
+        };
         stmt.analyze(analyzer);
 
         Assert.assertEquals("ALTER TABLE `testDb`.`testTbl` ENABLE FEATURE 
\"sequence_load\" WITH PROPERTIES (\"function_column.sequence_type\" = 
\"int\")",
@@ -134,6 +152,12 @@ public class AlterTableStmtTest {
                 new IndexDef("index1", false, Lists.newArrayList("col1"), 
IndexDef.IndexType.INVERTED, null, "balabala"),
                 true));
         AlterTableStmt stmt = new AlterTableStmt(new TableName(internalCtl, 
"testDb", "testTbl"), ops);
+        new Expectations() {
+            {
+                stmt.checkTemporaryTable();
+                minTimes = 0;
+            }
+        };
         stmt.analyze(analyzer);
         Assert.assertEquals("ALTER TABLE `testDb`.`testTbl` ADD INDEX `index1` 
(`col1`) USING INVERTED COMMENT 'balabala'",
                 stmt.toSql());
@@ -149,6 +173,12 @@ public class AlterTableStmtTest {
         List<AlterClause> ops = Lists.newArrayList();
         ops.add(createIndexClause);
         AlterTableStmt stmt = new AlterTableStmt(new TableName(internalCtl, 
"testDb", "testTbl"), ops);
+        new Expectations() {
+            {
+                stmt.checkTemporaryTable();
+                minTimes = 0;
+            }
+        };
         stmt.analyze(analyzer);
         Assert.assertEquals("CREATE INDEX `index1` ON `db`.`table` (`col1`) 
USING INVERTED COMMENT 'balabala'",
                 createIndexClause.toSql());
@@ -163,6 +193,12 @@ public class AlterTableStmtTest {
         ops.add(new DropIndexClause("index1", false,
                 new TableName(InternalCatalog.INTERNAL_CATALOG_NAME, "db", 
"table"), true));
         AlterTableStmt stmt = new AlterTableStmt(new TableName(internalCtl, 
"testDb", "testTbl"), ops);
+        new Expectations() {
+            {
+                stmt.checkTemporaryTable();
+                minTimes = 0;
+            }
+        };
         stmt.analyze(analyzer);
         Assert.assertEquals("ALTER TABLE `testDb`.`testTbl` DROP INDEX 
`index1`", stmt.toSql());
     }
@@ -175,6 +211,12 @@ public class AlterTableStmtTest {
         List<AlterClause> ops = Lists.newArrayList();
         ops.add(dropIndexClause);
         AlterTableStmt stmt = new AlterTableStmt(new TableName(internalCtl, 
"testDb", "testTbl"), ops);
+        new Expectations() {
+            {
+                stmt.checkTemporaryTable();
+                minTimes = 0;
+            }
+        };
         stmt.analyze(analyzer);
         Assert.assertEquals("DROP INDEX `index1` ON `db`.`table`", 
dropIndexClause.toSql());
         Assert.assertEquals("ALTER TABLE `testDb`.`testTbl` DROP INDEX 
`index1`", stmt.toSql());


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

Reply via email to