Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DropDataSrcStmt.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 
17 import org.apache.hadoop.hive.metastore.MetaStoreUtils;
18 
20 import com.cloudera.impala.thrift.TDropDataSourceParams;
21 import com.google.common.base.Preconditions;
22 
26 public class DropDataSrcStmt extends StatementBase {
27 
28  private final String dataSrcName_;
29  private final boolean ifExists_;
30 
31  public DropDataSrcStmt(String dataSrcName, boolean ifExists) {
32  Preconditions.checkNotNull(dataSrcName);
33  this.dataSrcName_ = dataSrcName.toLowerCase();
34  this.ifExists_ = ifExists;
35  }
36 
37  @Override
38  public void analyze(Analyzer analyzer) throws AnalysisException {
39  if (!MetaStoreUtils.validateName(dataSrcName_) ||
40  (!ifExists_ && analyzer.getCatalog().getDataSource(dataSrcName_) == null)) {
42  dataSrcName_);
43  }
44  }
45 
46  @Override
47  public String toSql() {
48  StringBuilder sb = new StringBuilder();
49  sb.append("DROP DATA SOURCE ");
50  if (ifExists_) sb.append("IF EXISTS ");
51  sb.append(dataSrcName_);
52  return sb.toString();
53  }
54 
55  public TDropDataSourceParams toThrift() {
56  return new TDropDataSourceParams(dataSrcName_).setIf_exists(ifExists_);
57  }
58 }
static final String DATA_SRC_DOES_NOT_EXIST_ERROR_MSG
Definition: Analyzer.java:113
DropDataSrcStmt(String dataSrcName, boolean ifExists)