Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ResetMetadataStmt.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.TResetMetadataRequest;
22 import com.cloudera.impala.thrift.TTableName;
23 import com.google.common.base.Preconditions;
24 
28 public class ResetMetadataStmt extends StatementBase {
29  // Updated during analysis. Null if invalidating the entire catalog.
31 
32  // true if it is a REFRESH statement.
33  private final boolean isRefresh_;
34 
36  Preconditions.checkArgument(!isRefresh || name != null);
37  this.tableName_ = name;
38  this.isRefresh_ = isRefresh;
39  }
40 
41  public TableName getTableName() { return tableName_; }
42  public boolean isRefresh() { return isRefresh_; }
43 
44  @Override
45  public void analyze(Analyzer analyzer) throws AnalysisException {
46  if (tableName_ != null) {
47  String dbName = analyzer.getTargetDbName(tableName_);
48  tableName_ = new TableName(dbName, tableName_.getTbl());
49 
50  if (isRefresh_) {
51  // Verify the user has privileges to access this table. Will throw if the parent
52  // database does not exists. Don't call getTable() to avoid loading the table
53  // metadata if it is not yet in this impalad's catalog cache.
54  if (!analyzer.dbContainsTable(dbName, tableName_.getTbl(), Privilege.ANY)) {
55  // Only throw an exception when the table does not exist for refresh statements
56  // since 'invalidate metadata' should add/remove tables created/dropped external
57  // to Impala.
59  }
60  } else {
61  // Verify the user has privileges to access this table.
62  analyzer.registerPrivReq(new PrivilegeRequestBuilder()
63  .onTable(dbName, tableName_.getTbl()).any().toRequest());
64  }
65  } else {
66  analyzer.registerPrivReq(new PrivilegeRequest(Privilege.ALL));
67  }
68  }
69 
70  @Override
71  public String toSql() {
72  StringBuilder result = new StringBuilder();
73  if (isRefresh_) {
74  result.append("INVALIDATE METADATA");
75  } else {
76  result.append("REFRESH");
77  }
78 
79  if (tableName_ != null) result.append(" ").append(tableName_);
80  return result.toString();
81  }
82 
83  public TResetMetadataRequest toThrift() {
84  TResetMetadataRequest params = new TResetMetadataRequest();
85  params.setIs_refresh(isRefresh_);
86  if (tableName_ != null) {
87  params.setTable_name(new TTableName(tableName_.getDb(), tableName_.getTbl()));
88  }
89  return params;
90  }
91 }
ResetMetadataStmt(TableName name, boolean isRefresh)
string name
Definition: cpu-info.cc:50
static final String TBL_DOES_NOT_EXIST_ERROR_MSG
Definition: Analyzer.java:109