use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.
the class MetadataCache method addFunctionIfNotExists.
public Function addFunctionIfNotExists(Function function) {
synchronized (functions) {
FunctionSignature signature = new FunctionSignature(function.getDataverseName(), function.getName(), function.getArity());
Function fun = functions.get(signature);
if (fun == null) {
return functions.put(signature, function);
}
return null;
}
}
use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.
the class FunctionInfoRepository method put.
public void put(FunctionIdentifier fid, IFunctionInfo fInfo) {
FunctionSignature functionSignature = new FunctionSignature(fid.getNamespace(), fid.getName(), fid.getArity());
functionMap.put(functionSignature, fInfo);
}
use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.
the class CommonFunctionMapUtil method normalizeBuiltinFunctionSignature.
/**
* Maps a user invoked function signature to a builtin internal function signature if possible.
*
* @param fs,
* the signature of an user typed function.
* @return the corresponding system internal function signature if it exists, otherwise
* the input function synature.
*/
public static FunctionSignature normalizeBuiltinFunctionSignature(FunctionSignature fs) throws CompilationException {
String name = fs.getName();
String lowerCaseName = name.toLowerCase();
String mappedName = FUNCTION_NAME_MAP.get(lowerCaseName);
if (mappedName != null) {
return new FunctionSignature(fs.getNamespace(), mappedName, fs.getArity());
}
String understoreName = lowerCaseName.replace('_', '-');
FunctionSignature newFs = new FunctionSignature(fs.getNamespace(), understoreName, fs.getArity());
return BuiltinFunctions.isBuiltinCompilerFunction(newFs, true) ? newFs : fs;
}
use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.
the class FunctionUtil method retrieveUsedStoredFunctions.
/**
* Retrieve stored functions (from CREATE FUNCTION statements) that have been used in an expression.
*
* @param metadataProvider,
* the metadata provider
* @param expression,
* the expression for analysis
* @param declaredFunctions,
* a set of declared functions in the query, which can potentially override stored functions.
* @param functionCollector,
* for collecting function calls in the <code>expression</code>
* @param functionParser,
* for parsing stored functions in the string represetnation.
* @param functionNormalizer,
* for normalizing function names.
* @throws CompilationException
*/
public static List<FunctionDecl> retrieveUsedStoredFunctions(MetadataProvider metadataProvider, Expression expression, List<FunctionSignature> declaredFunctions, List<FunctionDecl> inputFunctionDecls, IFunctionCollector functionCollector, IFunctionParser functionParser, IFunctionNormalizer functionNormalizer) throws CompilationException {
List<FunctionDecl> functionDecls = inputFunctionDecls == null ? new ArrayList<>() : new ArrayList<>(inputFunctionDecls);
if (expression == null) {
return functionDecls;
}
String value = metadataProvider.getConfig().get(FunctionUtil.IMPORT_PRIVATE_FUNCTIONS);
boolean includePrivateFunctions = (value != null) ? Boolean.valueOf(value.toLowerCase()) : false;
Set<FunctionSignature> functionCalls = functionCollector.getFunctionCalls(expression);
for (FunctionSignature signature : functionCalls) {
if (declaredFunctions != null && declaredFunctions.contains(signature)) {
continue;
}
if (signature.getNamespace() == null) {
signature.setNamespace(metadataProvider.getDefaultDataverseName());
}
String namespace = signature.getNamespace();
// Checks the existence of the referred dataverse.
if (metadataProvider.findDataverse(namespace) == null && !namespace.equals(FunctionConstants.ASTERIX_NS)) {
throw new CompilationException("In function call \"" + namespace + "." + signature.getName() + "(...)\", the dataverse \"" + namespace + "\" cannot be found!");
}
Function function = lookupUserDefinedFunctionDecl(metadataProvider.getMetadataTxnContext(), signature);
if (function == null) {
FunctionSignature normalizedSignature = functionNormalizer == null ? signature : functionNormalizer.normalizeBuiltinFunctionSignature(signature);
if (BuiltinFunctions.isBuiltinCompilerFunction(normalizedSignature, includePrivateFunctions)) {
continue;
}
StringBuilder messageBuilder = new StringBuilder();
if (!functionDecls.isEmpty()) {
messageBuilder.append("function " + functionDecls.get(functionDecls.size() - 1).getSignature() + " depends upon function " + signature + " which is undefined");
} else {
messageBuilder.append("function " + signature + " is not defined");
}
throw new CompilationException(messageBuilder.toString());
}
if (function.getLanguage().equalsIgnoreCase(Function.LANGUAGE_AQL)) {
FunctionDecl functionDecl = functionParser.getFunctionDecl(function);
if (functionDecl != null) {
if (functionDecls.contains(functionDecl)) {
throw new CompilationException("Recursive invocation " + functionDecls.get(functionDecls.size() - 1).getSignature() + " <==> " + functionDecl.getSignature());
}
functionDecls.add(functionDecl);
functionDecls = retrieveUsedStoredFunctions(metadataProvider, functionDecl.getFuncBody(), declaredFunctions, functionDecls, functionCollector, functionParser, functionNormalizer);
}
}
}
return functionDecls;
}
use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.
the class FormatPrintVisitor method visit.
@Override
public Void visit(FunctionDropStatement del, Integer step) throws CompilationException {
out.print(skip(step) + "drop function ");
FunctionSignature funcSignature = del.getFunctionSignature();
out.print(funcSignature.toString());
out.println(SEMICOLON);
return null;
}
Aggregations