Skip to content

Commit

Permalink
[BugFix] Drop inexistent table silently (#50150)
Browse files Browse the repository at this point in the history
Signed-off-by: Letian Jiang <[email protected]>
  • Loading branch information
letian-jiang authored Aug 23, 2024
1 parent 4d4ad5f commit aeff4a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,12 @@ public void dropTable(DropTableStmt stmt) throws DdlException {
hmsTable.getDbName(), hmsTable.getTableName(), table));
}
} else {
HiveTable hiveTable = (HiveTable) getTable(dbName, tableName);
HiveTable hiveTable = null;
try {
hiveTable = (HiveTable) getTable(dbName, tableName);
} catch (Exception e) {
// ignore not found exception
}
if (hiveTable == null && stmt.isSetIfExists()) {
LOG.warn("Table {}.{} doesn't exist", dbName, tableName);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
import com.starrocks.sql.ast.pipe.DropPipeStmt;
import com.starrocks.sql.ast.pipe.PipeName;
import com.starrocks.sql.ast.pipe.ShowPipeStmt;
import com.starrocks.sql.common.MetaUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -1482,14 +1483,22 @@ public Void visitDropTableStatement(DropTableStmt statement, ConnectContext cont
PrivilegeType.DROP.name(), ObjectType.VIEW.name(), statement.getTbl().getTbl());
}
} else {
Table table = null;
try {
table = MetaUtils.getTable(context, statement.getTbl());
Authorizer.checkTableAction(context.getCurrentUserIdentity(), context.getCurrentRoleIds(),
statement.getTbl(), PrivilegeType.DROP);
} catch (AccessDeniedException e) {
AccessDeniedException.reportAccessDenied(
statement.getTbl().getCatalog(),
context.getCurrentUserIdentity(), context.getCurrentRoleIds(),
PrivilegeType.DROP.name(), ObjectType.TABLE.name(), statement.getTbl().getTbl());
} catch (Exception e) {
if (table == null && statement.isSetIfExists()) {
// an exception will be thrown if table is not found, ignore it if `if exists` is set.
return null;
}
throw e;
}
}
return null;
Expand Down

0 comments on commit aeff4a3

Please sign in to comment.