Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DropFunctionStmt.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 
23 import com.cloudera.impala.thrift.TDropFunctionParams;
24 
30 public class DropFunctionStmt extends StatementBase {
31  private final FunctionName fnName_;
32  private final FunctionArgs fnArgs_;
33  private final boolean ifExists_;
34 
35  // Set in analyze().
36  private Function desc_;
37 
42  public DropFunctionStmt(FunctionName fnName, FunctionArgs fnArgs, boolean ifExists) {
43  fnName_ = fnName;
44  fnArgs_ = fnArgs;
45  ifExists_ = ifExists;
46  }
47 
48  public FunctionName getFunction() { return desc_.getFunctionName(); }
49  public boolean getIfExists() { return ifExists_; }
50 
51  @Override
52  public String toSql() {
53  StringBuilder sb = new StringBuilder("DROP FUNCTION");
54  if (ifExists_) sb.append(" IF EXISTS ");
55  sb.append(desc_.signatureString());
56  sb.append(")");
57  return sb.toString();
58  }
59 
60  public TDropFunctionParams toThrift() {
61  TDropFunctionParams params = new TDropFunctionParams();
62  params.setFn_name(desc_.getFunctionName().toThrift());
63  params.setArg_types(Type.toThrift(desc_.getArgs()));
64  params.setIf_exists(getIfExists());
65  params.setSignature(desc_.signatureString());
66  return params;
67  }
68 
69  @Override
70  public void analyze(Analyzer analyzer) throws AnalysisException {
71  fnName_.analyze(analyzer);
72  fnArgs_.analyze(analyzer);
73 
75  fnArgs_.hasVarArgs());
76 
77  // For now, if authorization is enabled, the user needs ALL on the server
78  // to drop functions.
79  // TODO: this is not the right granularity but acceptable for now.
80  analyzer.registerPrivReq(new PrivilegeRequest(
81  new AuthorizeableFn(desc_.signatureString()), Privilege.ALL));
82 
83  if (analyzer.getDb(desc_.dbName(), Privilege.DROP, false) == null && !ifExists_) {
84  throw new AnalysisException(Analyzer.DB_DOES_NOT_EXIST_ERROR_MSG + desc_.dbName());
85  }
86 
87  if (analyzer.getCatalog().getFunction(
88  desc_, Function.CompareMode.IS_IDENTICAL) == null && !ifExists_) {
89  throw new AnalysisException(
90  Analyzer.FN_DOES_NOT_EXIST_ERROR_MSG + desc_.signatureString());
91  }
92  }
93 }
DropFunctionStmt(FunctionName fnName, FunctionArgs fnArgs, boolean ifExists)
static final String DB_DOES_NOT_EXIST_ERROR_MSG
Definition: Analyzer.java:107
static final String FN_DOES_NOT_EXIST_ERROR_MSG
Definition: Analyzer.java:111
static final ScalarType INVALID
Definition: Type.java:44