Search in sources :

Example 16 with FunctionSignature

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;
    }
}
Also used : Function(org.apache.asterix.metadata.entities.Function) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature)

Example 17 with FunctionSignature

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);
}
Also used : FunctionSignature(org.apache.asterix.common.functions.FunctionSignature)

Example 18 with FunctionSignature

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;
}
Also used : FunctionSignature(org.apache.asterix.common.functions.FunctionSignature)

Example 19 with FunctionSignature

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;
}
Also used : CompilationException(org.apache.asterix.common.exceptions.CompilationException) Function(org.apache.asterix.metadata.entities.Function) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature) FunctionDecl(org.apache.asterix.lang.common.statement.FunctionDecl)

Example 20 with FunctionSignature

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;
}
Also used : FunctionSignature(org.apache.asterix.common.functions.FunctionSignature)

Aggregations

FunctionSignature (org.apache.asterix.common.functions.FunctionSignature)30 ArrayList (java.util.ArrayList)11 Expression (org.apache.asterix.lang.common.base.Expression)11 Function (org.apache.asterix.metadata.entities.Function)9 CompilationException (org.apache.asterix.common.exceptions.CompilationException)8 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)6 ACIDException (org.apache.asterix.common.exceptions.ACIDException)5 IOException (java.io.IOException)4 RemoteException (java.rmi.RemoteException)4 AsterixException (org.apache.asterix.common.exceptions.AsterixException)4 CallExpr (org.apache.asterix.lang.common.expression.CallExpr)4 LiteralExpr (org.apache.asterix.lang.common.expression.LiteralExpr)4 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)4 CaseExpression (org.apache.asterix.lang.sqlpp.expression.CaseExpression)4 MetadataException (org.apache.asterix.metadata.MetadataException)4 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)4 EntityId (org.apache.asterix.active.EntityId)3 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)3 MetadataTransactionContext (org.apache.asterix.metadata.MetadataTransactionContext)3 FeedConnection (org.apache.asterix.metadata.entities.FeedConnection)3