Search in sources :

Example 1 with AQLInlineUdfsVisitor

use of org.apache.asterix.lang.aql.visitor.AQLInlineUdfsVisitor in project asterixdb by apache.

the class AqlQueryRewriter method inlineDeclaredUdfs.

private void inlineDeclaredUdfs() throws CompilationException {
    if (topStatement == null) {
        return;
    }
    List<FunctionSignature> funIds = new ArrayList<FunctionSignature>();
    for (FunctionDecl fdecl : declaredFunctions) {
        funIds.add(fdecl.getSignature());
    }
    List<FunctionDecl> storedFunctionDecls = new ArrayList<>();
    for (Expression topLevelExpr : topStatement.getDirectlyEnclosedExpressions()) {
        storedFunctionDecls.addAll(FunctionUtil.retrieveUsedStoredFunctions(metadataProvider, topLevelExpr, funIds, null, expr -> getFunctionCalls(expr), func -> functionParser.getFunctionDecl(func), signature -> CommonFunctionMapUtil.normalizeBuiltinFunctionSignature(signature)));
        declaredFunctions.addAll(storedFunctionDecls);
    }
    if (!declaredFunctions.isEmpty()) {
        AQLInlineUdfsVisitor visitor = new AQLInlineUdfsVisitor(context, new AQLRewriterFactory(), declaredFunctions, metadataProvider);
        while (topStatement.accept(visitor, declaredFunctions)) {
        // loop until no more changes
        }
    }
    declaredFunctions.removeAll(storedFunctionDecls);
}
Also used : IAQLVisitor(org.apache.asterix.lang.aql.visitor.base.IAQLVisitor) ForClause(org.apache.asterix.lang.aql.clause.ForClause) DistinctClause(org.apache.asterix.lang.aql.clause.DistinctClause) ArrayList(java.util.ArrayList) GroupbyClause(org.apache.asterix.lang.common.clause.GroupbyClause) IReturningStatement(org.apache.asterix.lang.common.base.IReturningStatement) FunctionUtil(org.apache.asterix.lang.common.util.FunctionUtil) LetClause(org.apache.asterix.lang.common.clause.LetClause) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature) FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression) Kind(org.apache.asterix.lang.common.base.Expression.Kind) FunctionDecl(org.apache.asterix.lang.common.statement.FunctionDecl) CompilationException(org.apache.asterix.common.exceptions.CompilationException) AQLParserFactory(org.apache.asterix.lang.aql.parser.AQLParserFactory) Clause(org.apache.asterix.lang.common.base.Clause) Expression(org.apache.asterix.lang.common.base.Expression) Set(java.util.Set) LangRewritingContext(org.apache.asterix.lang.common.rewrites.LangRewritingContext) VarIdentifier(org.apache.asterix.lang.common.struct.VarIdentifier) CommonFunctionMapUtil(org.apache.asterix.lang.common.util.CommonFunctionMapUtil) IQueryRewriter(org.apache.asterix.lang.common.base.IQueryRewriter) GatherFunctionCallsVisitor(org.apache.asterix.lang.common.visitor.GatherFunctionCallsVisitor) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) List(java.util.List) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) MetadataProvider(org.apache.asterix.metadata.declared.MetadataProvider) AqlBuiltinFunctionRewriteVisitor(org.apache.asterix.lang.aql.rewrites.visitor.AqlBuiltinFunctionRewriteVisitor) AQLInlineUdfsVisitor(org.apache.asterix.lang.aql.visitor.AQLInlineUdfsVisitor) UnionExpr(org.apache.asterix.lang.aql.expression.UnionExpr) FunctionParser(org.apache.asterix.lang.aql.parser.FunctionParser) AQLInlineUdfsVisitor(org.apache.asterix.lang.aql.visitor.AQLInlineUdfsVisitor) FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression) Expression(org.apache.asterix.lang.common.base.Expression) ArrayList(java.util.ArrayList) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature) FunctionDecl(org.apache.asterix.lang.common.statement.FunctionDecl)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 CompilationException (org.apache.asterix.common.exceptions.CompilationException)1 FunctionSignature (org.apache.asterix.common.functions.FunctionSignature)1 DistinctClause (org.apache.asterix.lang.aql.clause.DistinctClause)1 ForClause (org.apache.asterix.lang.aql.clause.ForClause)1 FLWOGRExpression (org.apache.asterix.lang.aql.expression.FLWOGRExpression)1 UnionExpr (org.apache.asterix.lang.aql.expression.UnionExpr)1 AQLParserFactory (org.apache.asterix.lang.aql.parser.AQLParserFactory)1 FunctionParser (org.apache.asterix.lang.aql.parser.FunctionParser)1 AqlBuiltinFunctionRewriteVisitor (org.apache.asterix.lang.aql.rewrites.visitor.AqlBuiltinFunctionRewriteVisitor)1 AQLInlineUdfsVisitor (org.apache.asterix.lang.aql.visitor.AQLInlineUdfsVisitor)1 IAQLVisitor (org.apache.asterix.lang.aql.visitor.base.IAQLVisitor)1 Clause (org.apache.asterix.lang.common.base.Clause)1 Expression (org.apache.asterix.lang.common.base.Expression)1 Kind (org.apache.asterix.lang.common.base.Expression.Kind)1 IQueryRewriter (org.apache.asterix.lang.common.base.IQueryRewriter)1 IReturningStatement (org.apache.asterix.lang.common.base.IReturningStatement)1 GroupbyClause (org.apache.asterix.lang.common.clause.GroupbyClause)1