MCPcopy Create free account
hub / github.com/apache/impala / DropDbStmt

Class DropDbStmt

fe/src/main/java/org/apache/impala/analysis/DropDbStmt.java:28–101  ·  view source on GitHub ↗

Represents a DROP [IF EXISTS] DATABASE [CASCADE | RESTRICT] statement

Source from the content-addressed store, hash-verified

26 * Represents a DROP [IF EXISTS] DATABASE [CASCADE | RESTRICT] statement
27 */
28public class DropDbStmt extends StatementBase {
29 private final String dbName_;
30 private final boolean ifExists_;
31 private final boolean cascade_;
32
33 // Server name needed for privileges. Set during analysis.
34 private String serverName_;
35
36 /**
37 * Constructor for building the drop statement. If ifExists is true, an error will not
38 * be thrown if the database does not exist. If cascade is true, all the tables in the
39 * database will be dropped.
40 */
41 public DropDbStmt(String dbName, boolean ifExists, boolean cascade) {
42 this.dbName_ = dbName;
43 this.ifExists_ = ifExists;
44 this.cascade_ = cascade;
45 }
46
47 @Override
48 public String getParsedDb() { return dbName_; }
49 public String getDb() { return dbName_; }
50 public boolean getIfExists() { return ifExists_; }
51 public boolean getCascade() { return cascade_; }
52
53 @Override
54 public String toSql(ToSqlOptions options) {
55 StringBuilder sb = new StringBuilder("DROP DATABASE");
56 if (ifExists_) sb.append(" IF EXISTS ");
57 sb.append(getDb());
58 if (cascade_) sb.append(" CASCADE");
59 return sb.toString();
60 }
61
62 public TDropDbParams toThrift() {
63 TDropDbParams params = new TDropDbParams();
64 params.setDb(getDb());
65 params.setIf_exists(getIfExists());
66 params.setCascade(getCascade());
67 params.setServer_name(serverName_);
68 return params;
69 }
70
71 @Override
72 public void analyze(Analyzer analyzer) throws AnalysisException {
73 // Set the servername here if authorization is enabled because analyzer_ is not
74 // available in the toThrift() method.
75 serverName_ = analyzer.getServerName();
76 // Fetch the owner information if the db exists.
77 FeDb db = analyzer.getDb(dbName_, /*ThrowIfNotExists*/ false);
78 String ownerUser = db == null ? null : db.getOwnerUser();
79 if (ifExists_) {
80 // Start with ANY privilege in case of IF EXISTS, and register DROP privilege
81 // later only if the database exists. See IMPALA-8851 for more explanation.
82 analyzer.registerPrivReq(builder ->
83 builder.allOf(Privilege.ANY)
84 .onDb(dbName_, ownerUser)
85 .build());

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected