Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DropStatsStmt.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.TDropStatsParams;
21 import com.cloudera.impala.thrift.TTableName;
22 import com.google.common.base.Preconditions;
23 
28 public class DropStatsStmt extends StatementBase {
29  protected final TableName tableName_;
30 
31  // If non-null, only drop the statistics for a given partition
33 
34  // Set during analysis
35  protected String dbName_;
36 
40  public DropStatsStmt(TableName tableName) {
41  this.tableName_ = tableName;
42  }
43 
44  public DropStatsStmt(TableName tableName, PartitionSpec partSpec) {
45  this.tableName_ = tableName;
46  this.partitionSpec_ = partSpec;
47  }
48 
49  @Override
50  public String toSql() {
51  StringBuilder sb = new StringBuilder("DROP ");
52  if (partitionSpec_ == null) {
53  sb.append(" STATS ");
54  if (tableName_.getDb() != null) sb.append(tableName_.getDb() + ".");
55  sb.append(tableName_.toSql());
56  } else {
57  sb.append(" INCREMENTAL STATS ");
58  if (tableName_.getDb() != null) sb.append(tableName_.getDb() + ".");
59  sb.append(tableName_.toSql());
60  sb.append(partitionSpec_.toSql());
61  }
62  return sb.toString();
63  }
64 
65  public TDropStatsParams toThrift() {
66  TDropStatsParams params = new TDropStatsParams();
67  params.setTable_name(new TTableName(getDb(), getTbl()));
68 
69  if (partitionSpec_ != null) {
70  params.setPartition_spec(partitionSpec_.toThrift());
71  }
72  return params;
73  }
74 
79  @Override
80  public void analyze(Analyzer analyzer) throws AnalysisException {
81  dbName_ = analyzer.getTargetDbName(tableName_);
82  Table table = analyzer.getTable(tableName_, Privilege.ALTER);
83  Preconditions.checkNotNull(table);
84  if (partitionSpec_ != null) {
85  partitionSpec_.setTableName(tableName_);
86  partitionSpec_.setPrivilegeRequirement(Privilege.ALTER);
87  partitionSpec_.setPartitionShouldExist();
88  partitionSpec_.analyze(analyzer);
89  }
90  }
91 
96  public String getDb() {
97  Preconditions.checkNotNull(dbName_);
98  return dbName_;
99  }
100 
101  public String getTbl() { return tableName_.getTbl(); }
102 }
DropStatsStmt(TableName tableName, PartitionSpec partSpec)