15 package com.cloudera.impala.analysis;
17 import java.util.ArrayList;
18 import java.util.HashMap;
19 import java.util.List;
21 import org.apache.hadoop.fs.permission.FsAction;
31 import com.cloudera.impala.thrift.TCreateFunctionParams;
32 import com.cloudera.impala.thrift.TFunctionBinaryType;
33 import com.google.common.collect.Lists;
56 protected final HashMap<CreateFunctionStmtBase.OptArg, String>
optArgs_;
67 HashMap<CreateFunctionStmtBase.OptArg, String> optArgs) {
80 TCreateFunctionParams params =
new TCreateFunctionParams(
fn_.
toThrift());
82 params.setFn(fn_.toThrift());
92 return optArgs_.get(key);
98 throw new AnalysisException(
"Optional argument '" + key +
"' should not be set.");
104 TFunctionBinaryType binaryType = null;
105 String binaryPath = fn_.getLocation().getLocation();
106 int suffixIndex = binaryPath.lastIndexOf(
".");
107 if (suffixIndex != -1) {
108 String suffix = binaryPath.substring(suffixIndex + 1);
109 if (suffix.equalsIgnoreCase(
"jar")) {
110 binaryType = TFunctionBinaryType.HIVE;
111 }
else if (suffix.equalsIgnoreCase(
"so")) {
112 binaryType = TFunctionBinaryType.NATIVE;
113 }
else if (suffix.equalsIgnoreCase(
"ll")) {
114 binaryType = TFunctionBinaryType.IR;
117 if (binaryType == null) {
118 throw new AnalysisException(
"Unknown binary type: '" + binaryPath +
119 "'. Binary must end in .jar, .so or .ll");
127 fnName_.analyze(analyzer);
130 args_.analyze(analyzer);
131 retTypeDef_.analyze(analyzer);
143 if (builtinsDb.containsFunction(fn_.getName())) {
144 throw new AnalysisException(
"Function cannot have the same name as a builtin: " +
145 fn_.getFunctionName().getFunction());
149 List<Type> refdTypes = Lists.newArrayList(fn_.getReturnType());
150 refdTypes.addAll(Lists.newArrayList(fn_.getArgs()));
151 for (
Type t: refdTypes) {
152 if (!t.isSupported() || t.isComplexType()) {
154 String.format(
"Type '%s' is not supported in UDFs/UDAs.", t.toSql()));
162 Function existingFn = analyzer.getCatalog().getFunction(
163 fn_,
Function.CompareMode.IS_INDISTINGUISHABLE);
180 ArrayList<Type> argTypes,
Type retType,
boolean hasVarArgs);
void checkOptArgNotSet(OptArg key)
String checkAndGetOptArg(OptArg key)
final HashMap< CreateFunctionStmtBase.OptArg, String > optArgs_
TFunctionBinaryType getBinaryType()
static final String BUILTINS_DB
final FunctionName fnName_
final TypeDef retTypeDef_
abstract Function createFunction(FunctionName fnName, ArrayList< Type > argTypes, Type retType, boolean hasVarArgs)
ArrayList< Type > getArgTypes()
static final String DB_DOES_NOT_EXIST_ERROR_MSG
void analyze(Analyzer analyzer)
TCreateFunctionParams toThrift()
CreateFunctionStmtBase(FunctionName fnName, FunctionArgs args, TypeDef retTypeDef, HdfsUri location, boolean ifNotExists, HashMap< CreateFunctionStmtBase.OptArg, String > optArgs)
final boolean ifNotExists_
static final String FN_ALREADY_EXISTS_ERROR_MSG