Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ShowStatsStmt.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 
21 import com.cloudera.impala.thrift.TShowStatsParams;
22 
27 public class ShowStatsStmt extends StatementBase {
28  protected final boolean isShowColStats_;
29  protected final TableName tableName_;
30 
31  // Set during analysis.
32  protected Table table_;
33 
34  public ShowStatsStmt(TableName tableName, boolean isShowColStats) {
35  this.tableName_ = tableName;
36  this.isShowColStats_ = isShowColStats;
37  }
38 
39  @Override
40  public String toSql() {
41  return getSqlPrefix() + " " + tableName_.toString();
42  }
43 
44  protected String getSqlPrefix() {
45  return "SHOW " + ((isShowColStats_) ? "COLUMN" : "TABLE") + " STATS";
46  }
47 
48  @Override
49  public void analyze(Analyzer analyzer) throws AnalysisException {
50  table_ = analyzer.getTable(tableName_, Privilege.VIEW_METADATA);
51  if (table_ instanceof View) {
52  throw new AnalysisException(String.format(
53  "%s not applicable to a view: %s", getSqlPrefix(), table_.getFullName()));
54  }
55  }
56 
57  public TShowStatsParams toThrift() {
58  // Ensure the DB is set in the table_name field by using table and not tableName.
59  return new TShowStatsParams(isShowColStats_,
60  new TableName(table_.getDb().getName(), table_.getName()).toThrift());
61  }
62 }
ShowStatsStmt(TableName tableName, boolean isShowColStats)