Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
AlterTableDropPartitionStmt.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 
19 import com.cloudera.impala.thrift.TAlterTableDropPartitionParams;
20 import com.cloudera.impala.thrift.TAlterTableParams;
21 import com.cloudera.impala.thrift.TAlterTableType;
22 import com.google.common.base.Preconditions;
23 
28  private final boolean ifExists_;
30 
32  PartitionSpec partitionSpec, boolean ifExists) {
33  super(tableName);
34  Preconditions.checkNotNull(partitionSpec);
35  partitionSpec_ = partitionSpec;
36  partitionSpec_.setTableName(tableName);
37  ifExists_ = ifExists;
38  }
39 
40  public boolean getIfNotExists() { return ifExists_; }
41 
42  @Override
43  public String toSql() {
44  StringBuilder sb = new StringBuilder("ALTER TABLE " + getTbl());
45  sb.append(" DROP ");
46  if (ifExists_) sb.append("IF EXISTS ");
47  sb.append(" DROP " + partitionSpec_.toSql());
48  return sb.toString();
49  }
50 
51  @Override
52  public TAlterTableParams toThrift() {
53  TAlterTableParams params = super.toThrift();
54  params.setAlter_type(TAlterTableType.DROP_PARTITION);
55  TAlterTableDropPartitionParams addPartParams = new TAlterTableDropPartitionParams();
56  addPartParams.setPartition_spec(partitionSpec_.toThrift());
57  addPartParams.setIf_exists(ifExists_);
58  params.setDrop_partition_params(addPartParams);
59  return params;
60  }
61 
62  @Override
63  public void analyze(Analyzer analyzer) throws AnalysisException {
64  super.analyze(analyzer);
65  if (!ifExists_) partitionSpec_.setPartitionShouldExist();
66  partitionSpec_.setPrivilegeRequirement(Privilege.ALTER);
67  partitionSpec_.analyze(analyzer);
68  }
69 }
AlterTableDropPartitionStmt(TableName tableName, PartitionSpec partitionSpec, boolean ifExists)