Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
AlterTableStmt.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 
22 import com.cloudera.impala.thrift.TAlterTableParams;
23 import com.cloudera.impala.thrift.TTableName;
24 import com.google.common.base.Preconditions;
25 
29 public abstract class AlterTableStmt extends StatementBase {
30  protected final TableName tableName_;
31 
32  // Set during analysis.
33  protected Table table_;
34 
35  protected AlterTableStmt(TableName tableName) {
36  Preconditions.checkState(tableName != null && !tableName.isEmpty());
37  tableName_ = tableName;
38  table_ = null;
39  }
40 
41  public String getTbl() { return tableName_.getTbl(); }
42 
47  public String getDb() {
48  return getTargetTable().getDb().getName();
49  }
50 
55  protected Table getTargetTable() {
56  Preconditions.checkNotNull(table_);
57  return table_;
58  }
59 
60  public TAlterTableParams toThrift() {
61  TAlterTableParams params = new TAlterTableParams();
62  params.setTable_name(new TTableName(getDb(), getTbl()));
63  return params;
64  }
65 
66  @Override
67  public void analyze(Analyzer analyzer) throws AnalysisException {
68  table_ = analyzer.getTable(tableName_, Privilege.ALTER);
69  if (table_ instanceof View) {
70  throw new AnalysisException(String.format(
71  "ALTER TABLE not allowed on a view: %s", table_.getFullName()));
72  }
73  if (table_ instanceof DataSourceTable) {
74  throw new AnalysisException(String.format(
75  "ALTER TABLE not allowed on a table produced by a data source: %s",
76  table_.getFullName()));
77  }
78  }
79 }