[fix](auth)fix create table like need create_priv of existed table (#… (#38570)
…37879) pick: https://github.com/apache/doris/pull/37879
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user