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
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 60091f072a8 [fix](auth)fix create table like need create_priv of
existed table (#… (#38570)
60091f072a8 is described below
commit 60091f072a8fbb8fe6f8720deb76791b927ffdcc
Author: zhangdong <[email protected]>
AuthorDate: Thu Aug 1 18:57:44 2024 +0800
[fix](auth)fix create table like need create_priv of existed table (#…
(#38570)
…37879)
pick: https://github.com/apache/doris/pull/37879
---
.../apache/doris/datasource/InternalCatalog.java | 24 ++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
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 83af49508ea..992a8232dfb 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
@@ -190,6 +190,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
@@ -1166,6 +1167,8 @@ public class InternalCatalog implements
CatalogIf<Database> {
}
public void createTableLike(CreateTableLikeStmt stmt) throws DdlException {
+ ConnectContext ctx = ConnectContext.get();
+ Objects.requireNonNull(ctx, "ConnectContext.get() can not be null.");
try {
DatabaseIf db = getDbOrDdlException(stmt.getExistedDbName());
TableIf table =
db.getTableOrDdlException(stmt.getExistedTableName());
@@ -1199,14 +1202,23 @@ public class InternalCatalog implements
CatalogIf<Database> {
} finally {
table.readUnlock();
}
- CreateTableStmt parsedCreateTableStmt = (CreateTableStmt)
SqlParserUtils.parseAndAnalyzeStmt(
- createTableStmt.get(0), ConnectContext.get());
- parsedCreateTableStmt.setTableName(stmt.getTableName());
- parsedCreateTableStmt.setIfNotExists(stmt.isIfNotExists());
- createTable(parsedCreateTableStmt);
+
+ try {
+ // analyze CreateTableStmt will check create_priv of
existedTable, create table like only need
+ // create_priv of newTable, and select_priv of existedTable,
and priv check has done in
+ // CreateTableStmt/CreateTableCommand, so we skip it
+ ctx.setSkipAuth(true);
+ CreateTableStmt parsedCreateTableStmt = (CreateTableStmt)
SqlParserUtils.parseAndAnalyzeStmt(
+ createTableStmt.get(0), ctx);
+ parsedCreateTableStmt.setTableName(stmt.getTableName());
+ parsedCreateTableStmt.setIfNotExists(stmt.isIfNotExists());
+ createTable(parsedCreateTableStmt);
+ } finally {
+ ctx.setSkipAuth(false);
+ }
} catch (UserException e) {
throw new DdlException("Failed to execute CREATE TABLE LIKE " +
stmt.getExistedTableName() + ". Reason: "
- + e.getMessage());
+ + e.getMessage(), e);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]