Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ShowFunctionsStmt.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.TFunctionCategory;
20 import com.cloudera.impala.thrift.TShowFunctionsParams;
21 import com.google.common.base.Preconditions;
22 
31 public class ShowFunctionsStmt extends StatementBase {
32  // Pattern to match tables against. | denotes choice, * matches all strings
33  private final String pattern_;
34 
35  // DB (if any) as seen by the parser
36  private final String parsedDb_;
37 
38  // Category of functions to be shown. Always set.
39  private final TFunctionCategory fnCategory_;
40 
41  // Set during analysis
42  private String postAnalysisDb_;
43 
48  public ShowFunctionsStmt(String db, String pattern, TFunctionCategory fnCategory) {
49  Preconditions.checkNotNull(fnCategory);
50  parsedDb_ = db;
51  pattern_ = pattern;
52  fnCategory_ = fnCategory;
53  }
54 
59  public String getDb() {
60  Preconditions.checkNotNull(postAnalysisDb_);
61  return postAnalysisDb_;
62  }
63 
64  public String getPattern() { return pattern_; }
65 
66  @Override
67  public String toSql() {
68  String fnCategory = (fnCategory_ == null) ? "" : fnCategory_.toString() + " ";
69  if (pattern_ == null) {
70  return "SHOW " + fnCategory + "FUNCTIONS";
71  } else {
72  return "SHOW " + fnCategory + "FUNCTIONS LIKE '" + pattern_ + "'";
73  }
74  }
75 
76  @Override
77  public void analyze(Analyzer analyzer) throws AnalysisException {
78  postAnalysisDb_ = (parsedDb_ == null ? analyzer.getDefaultDb() : parsedDb_);
79  if (analyzer.getDb(postAnalysisDb_, Privilege.VIEW_METADATA) == null) {
81  }
82  }
83 
84  public TShowFunctionsParams toThrift() {
85  TShowFunctionsParams params = new TShowFunctionsParams();
86  params.setCategory(fnCategory_);
87  params.setDb(getDb());
88  params.setShow_pattern(getPattern());
89  return params;
90  }
91 }
ShowFunctionsStmt(String db, String pattern, TFunctionCategory fnCategory)
static final String DB_DOES_NOT_EXIST_ERROR_MSG
Definition: Analyzer.java:107