Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DropDbStmt.java
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package com.cloudera.impala.analysis;
16 
20 import com.cloudera.impala.thrift.TDropDbParams;
21 
25 public class DropDbStmt extends StatementBase {
26  private final String dbName_;
27  private final boolean ifExists_;
28 
33  public DropDbStmt(String dbName, boolean ifExists) {
34  this.dbName_ = dbName;
35  this.ifExists_ = ifExists;
36  }
37 
38  public String getDb() { return dbName_; }
39  public boolean getIfExists() { return ifExists_; }
40 
41  @Override
42  public String toSql() {
43  StringBuilder sb = new StringBuilder("DROP DATABASE");
44  if (ifExists_) {
45  sb.append(" IF EXISTS ");
46  }
47  sb.append(getDb());
48  return sb.toString();
49  }
50 
51  public TDropDbParams toThrift() {
52  TDropDbParams params = new TDropDbParams();
53  params.setDb(getDb());
54  params.setIf_exists(getIfExists());
55  return params;
56  }
57 
58  @Override
59  public void analyze(Analyzer analyzer) throws AnalysisException {
60  Db db = analyzer.getDb(dbName_, Privilege.DROP, false);
61  if (db == null && !ifExists_) {
63  }
64 
65  if (analyzer.getDefaultDb().toLowerCase().equals(dbName_.toLowerCase())) {
66  throw new AnalysisException("Cannot drop current default database: " + dbName_);
67  }
68  if (db != null && db.numFunctions() > 0) {
69  throw new AnalysisException("Cannot drop non-empty database: " + dbName_);
70  }
71  }
72 }
DropDbStmt(String dbName, boolean ifExists)
Definition: DropDbStmt.java:33
static final String DB_DOES_NOT_EXIST_ERROR_MSG
Definition: Analyzer.java:107