Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ShowTablesStmt.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 
19 import com.cloudera.impala.thrift.TShowTablesParams;
20 import com.google.common.base.Preconditions;
21 
36 public class ShowTablesStmt extends StatementBase {
37  // Pattern to match tables against. | denotes choice, * matches all strings
38  private final String pattern_;
39 
40  // DB (if any) as seen by the parser
41  private final String parsedDb_;
42 
43  // Set during analysis
44  private String postAnalysisDb_;
45 
50  public ShowTablesStmt() {
51  this(null, null);
52  }
53 
58  public ShowTablesStmt(String pattern) {
59  this(null, pattern);
60  }
61 
69  public ShowTablesStmt(String database, String pattern) {
70  this.parsedDb_ = database;
71  this.pattern_ = pattern;
72  this.postAnalysisDb_ = null;
73  }
74 
75  public String getPattern() { return pattern_; }
76 
81  public String getDb() {
82  Preconditions.checkNotNull(postAnalysisDb_);
83  return postAnalysisDb_;
84  }
85 
86  @Override
87  public String toSql() {
88  if (pattern_ == null) {
89  if (parsedDb_ == null) {
90  return "SHOW TABLES";
91  } else {
92  return "SHOW TABLES IN " + parsedDb_;
93  }
94  } else {
95  if (parsedDb_ == null) {
96  return "SHOW TABLES LIKE '" + pattern_ + "'";
97  } else {
98  return "SHOW TABLES IN " + parsedDb_ + " LIKE '" + pattern_ + "'";
99  }
100  }
101  }
102 
103  @Override
104  public void analyze(Analyzer analyzer) throws AnalysisException {
105  postAnalysisDb_ = (parsedDb_ == null ? analyzer.getDefaultDb() : parsedDb_);
106  if (analyzer.getDb(postAnalysisDb_, Privilege.ANY) == null) {
108  }
109  }
110 
111  public TShowTablesParams toThrift() {
112  TShowTablesParams params = new TShowTablesParams();
113  params.setShow_pattern(getPattern());
114  params.setDb(getDb());
115  return params;
116  }
117 }
ShowTablesStmt(String database, String pattern)
static final String DB_DOES_NOT_EXIST_ERROR_MSG
Definition: Analyzer.java:107