Search in sources :

Example 1 with SqlppInlineUdfsVisitor

use of org.apache.asterix.lang.sqlpp.rewrites.visitor.SqlppInlineUdfsVisitor in project asterixdb by apache.

the class SqlppQueryRewriter method inlineDeclaredUdfs.

protected void inlineDeclaredUdfs() throws CompilationException {
    List<FunctionSignature> funIds = new ArrayList<FunctionSignature>();
    for (FunctionDecl fdecl : declaredFunctions) {
        funIds.add(fdecl.getSignature());
    }
    List<FunctionDecl> usedStoredFunctionDecls = new ArrayList<>();
    for (Expression topLevelExpr : topExpr.getDirectlyEnclosedExpressions()) {
        usedStoredFunctionDecls.addAll(FunctionUtil.retrieveUsedStoredFunctions(metadataProvider, topLevelExpr, funIds, null, expr -> getFunctionCalls(expr), func -> functionRepository.getFunctionDecl(func), signature -> FunctionMapUtil.normalizeBuiltinFunctionSignature(signature, false)));
    }
    declaredFunctions.addAll(usedStoredFunctionDecls);
    if (!declaredFunctions.isEmpty()) {
        SqlppInlineUdfsVisitor visitor = new SqlppInlineUdfsVisitor(context, new SqlppFunctionBodyRewriterFactory(), /* the rewriter for function bodies expressions*/
        declaredFunctions, metadataProvider);
        while (topExpr.accept(visitor, declaredFunctions)) {
        // loop until no more changes
        }
    }
    declaredFunctions.removeAll(usedStoredFunctionDecls);
}
Also used : UnnestClause(org.apache.asterix.lang.sqlpp.clause.UnnestClause) OperatorExpressionVisitor(org.apache.asterix.lang.sqlpp.rewrites.visitor.OperatorExpressionVisitor) JoinClause(org.apache.asterix.lang.sqlpp.clause.JoinClause) FromTerm(org.apache.asterix.lang.sqlpp.clause.FromTerm) VariableCheckAndRewriteVisitor(org.apache.asterix.lang.sqlpp.rewrites.visitor.VariableCheckAndRewriteVisitor) SqlppGlobalAggregationSugarVisitor(org.apache.asterix.lang.sqlpp.rewrites.visitor.SqlppGlobalAggregationSugarVisitor) InlineColumnAliasVisitor(org.apache.asterix.lang.sqlpp.rewrites.visitor.InlineColumnAliasVisitor) SelectElement(org.apache.asterix.lang.sqlpp.clause.SelectElement) SelectRegular(org.apache.asterix.lang.sqlpp.clause.SelectRegular) FunctionParser(org.apache.asterix.lang.sqlpp.parser.FunctionParser) NestClause(org.apache.asterix.lang.sqlpp.clause.NestClause) ArrayList(java.util.ArrayList) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression) HavingClause(org.apache.asterix.lang.sqlpp.clause.HavingClause) IReturningStatement(org.apache.asterix.lang.common.base.IReturningStatement) ISqlppVisitor(org.apache.asterix.lang.sqlpp.visitor.base.ISqlppVisitor) FunctionUtil(org.apache.asterix.lang.common.util.FunctionUtil) LetClause(org.apache.asterix.lang.common.clause.LetClause) SubstituteGroupbyExpressionWithVariableVisitor(org.apache.asterix.lang.sqlpp.rewrites.visitor.SubstituteGroupbyExpressionWithVariableVisitor) SqlppListInputFunctionRewriteVisitor(org.apache.asterix.lang.sqlpp.rewrites.visitor.SqlppListInputFunctionRewriteVisitor) SetOperationRight(org.apache.asterix.lang.sqlpp.struct.SetOperationRight) SelectBlock(org.apache.asterix.lang.sqlpp.clause.SelectBlock) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature) SelectSetOperation(org.apache.asterix.lang.sqlpp.clause.SelectSetOperation) FunctionDecl(org.apache.asterix.lang.common.statement.FunctionDecl) CompilationException(org.apache.asterix.common.exceptions.CompilationException) SelectClause(org.apache.asterix.lang.sqlpp.clause.SelectClause) SqlppInlineUdfsVisitor(org.apache.asterix.lang.sqlpp.rewrites.visitor.SqlppInlineUdfsVisitor) SqlppGroupByVisitor(org.apache.asterix.lang.sqlpp.rewrites.visitor.SqlppGroupByVisitor) Expression(org.apache.asterix.lang.common.base.Expression) Set(java.util.Set) LangRewritingContext(org.apache.asterix.lang.common.rewrites.LangRewritingContext) Projection(org.apache.asterix.lang.sqlpp.clause.Projection) AbstractBinaryCorrelateClause(org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause) SqlppParserFactory(org.apache.asterix.lang.sqlpp.parser.SqlppParserFactory) IQueryRewriter(org.apache.asterix.lang.common.base.IQueryRewriter) SqlppBuiltinFunctionRewriteVisitor(org.apache.asterix.lang.sqlpp.rewrites.visitor.SqlppBuiltinFunctionRewriteVisitor) GatherFunctionCallsVisitor(org.apache.asterix.lang.common.visitor.GatherFunctionCallsVisitor) List(java.util.List) MetadataProvider(org.apache.asterix.metadata.declared.MetadataProvider) GenerateColumnNameVisitor(org.apache.asterix.lang.sqlpp.rewrites.visitor.GenerateColumnNameVisitor) FunctionMapUtil(org.apache.asterix.lang.sqlpp.util.FunctionMapUtil) InlineWithExpressionVisitor(org.apache.asterix.lang.sqlpp.rewrites.visitor.InlineWithExpressionVisitor) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) FromClause(org.apache.asterix.lang.sqlpp.clause.FromClause) IndependentSubquery(org.apache.asterix.lang.sqlpp.expression.IndependentSubquery) SetOperationVisitor(org.apache.asterix.lang.sqlpp.rewrites.visitor.SetOperationVisitor) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression) Expression(org.apache.asterix.lang.common.base.Expression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) ArrayList(java.util.ArrayList) SqlppInlineUdfsVisitor(org.apache.asterix.lang.sqlpp.rewrites.visitor.SqlppInlineUdfsVisitor) 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 Expression (org.apache.asterix.lang.common.base.Expression)1 IQueryRewriter (org.apache.asterix.lang.common.base.IQueryRewriter)1 IReturningStatement (org.apache.asterix.lang.common.base.IReturningStatement)1 LetClause (org.apache.asterix.lang.common.clause.LetClause)1 LangRewritingContext (org.apache.asterix.lang.common.rewrites.LangRewritingContext)1 FunctionDecl (org.apache.asterix.lang.common.statement.FunctionDecl)1 FunctionUtil (org.apache.asterix.lang.common.util.FunctionUtil)1 GatherFunctionCallsVisitor (org.apache.asterix.lang.common.visitor.GatherFunctionCallsVisitor)1 AbstractBinaryCorrelateClause (org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause)1 FromClause (org.apache.asterix.lang.sqlpp.clause.FromClause)1 FromTerm (org.apache.asterix.lang.sqlpp.clause.FromTerm)1 HavingClause (org.apache.asterix.lang.sqlpp.clause.HavingClause)1 JoinClause (org.apache.asterix.lang.sqlpp.clause.JoinClause)1 NestClause (org.apache.asterix.lang.sqlpp.clause.NestClause)1 Projection (org.apache.asterix.lang.sqlpp.clause.Projection)1