Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
AlterViewStmt.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 
23 import com.google.common.base.Preconditions;
24 
29 
30  public AlterViewStmt(TableName tableName, QueryStmt viewDefStmt) {
31  super(false, tableName, null, null, viewDefStmt);
32  }
33 
34  @Override
35  public void analyze(Analyzer analyzer) throws AnalysisException {
36  // Enforce Hive column labels for view compatibility.
37  analyzer.setUseHiveColLabels(true);
38  viewDefStmt_.analyze(analyzer);
39 
40  Preconditions.checkState(tableName_ != null && !tableName_.isEmpty());
41  dbName_ = analyzer.getTargetDbName(tableName_);
42  owner_ = analyzer.getUser().getName();
43 
44  Table table = analyzer.getTable(tableName_, Privilege.ALTER);
45  Preconditions.checkNotNull(table);
46  if (!(table instanceof View)) {
47  throw new AnalysisException(String.format(
48  "ALTER VIEW not allowed on a table: %s.%s", dbName_, getTbl()));
49  }
50 
51  createColumnAndViewDefs(analyzer);
52  if (RuntimeEnv.INSTANCE.computeLineage() || RuntimeEnv.INSTANCE.isTestEnv()) {
53  computeLineageGraph(analyzer);
54  }
55  }
56 
57  @Override
58  public String toSql() {
59  StringBuilder sb = new StringBuilder();
60  sb.append("ALTER VIEW ");
61  if (tableName_.getDb() != null) {
62  sb.append(tableName_.getDb() + ".");
63  }
64  sb.append(tableName_.getTbl());
65  sb.append(" AS " + viewDefStmt_.toSql());
66  return sb.toString();
67  }
68 }
AlterViewStmt(TableName tableName, QueryStmt viewDefStmt)