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);
}
Aggregations