in asterix-graphix/src/main/java/org/apache/asterix/graphix/lang/rewrite/lower/action/AbstractInlineAction.java [73:133]
public void apply(LoweringEnvironment loweringEnvironment) throws CompilationException {
final Function<VariableExpr, VariableExpr> substitutionAdder = v -> {
VariableExpr reboundVariableExpr = graphixRewritingContext.getGraphixVariableCopy(v);
remapCloneVisitor.addSubstitution(v, reboundVariableExpr);
return reboundVariableExpr;
};
// To inline, we need to ensure that we substitute variables accordingly.
remapCloneVisitor.resetSubstitutions();
if (bodyAnalysisContext.getFromTermVariable() != null) {
VariableExpr fromTermVariableExpr = bodyAnalysisContext.getFromTermVariable();
VariableExpr elementVariableExpr = new VariableExpr(elementVariable.getVar());
remapCloneVisitor.addSubstitution(fromTermVariableExpr, elementVariableExpr);
}
// If we have any UNNEST clauses, we need to add these.
if (bodyAnalysisContext.getUnnestClauses() != null) {
for (AbstractBinaryCorrelateClause unnestClause : bodyAnalysisContext.getUnnestClauses()) {
loweringEnvironment.acceptTransformer(lowerList -> {
UnnestClause copiedClause = (UnnestClause) remapCloneVisitor.substitute(unnestClause);
if (copiedClause.hasPositionalVariable()) {
substitutionAdder.apply(copiedClause.getPositionalVariable());
}
VariableExpr reboundUnnestVariable = substitutionAdder.apply(copiedClause.getRightVariable());
UnnestClause newUnnestClause =
new UnnestClause(copiedClause.getUnnestType(), copiedClause.getRightExpression(),
reboundUnnestVariable, null, copiedClause.getOuterUnnestMissingValueType());
newUnnestClause.setSourceLocation(unnestClause.getSourceLocation());
lowerList.addNonRepresentativeClause(newUnnestClause);
});
}
}
// If we have any LET clauses, we need to substitute them in our WHERE and SELECT clauses.
if (bodyAnalysisContext.getLetClauses() != null) {
for (LetClause letClause : bodyAnalysisContext.getLetClauses()) {
// Remap this LET-CLAUSE to include our new variables. Move this to our correlated clauses.
LetClause copiedClause = (LetClause) remapCloneVisitor.substitute(letClause);
VariableExpr reboundLetVariable = substitutionAdder.apply(copiedClause.getVarExpr());
VariableExpr reboundLetVariableCopy = deepCopyVisitor.visit(reboundLetVariable, null);
Expression copiedBindingExpr = copiedClause.getBindingExpr();
loweringEnvironment.acceptTransformer(lowerList -> {
LetClause reboundLetClause = new LetClause(reboundLetVariableCopy, copiedBindingExpr);
reboundLetClause.setSourceLocation(letClause.getSourceLocation());
lowerList.addNonRepresentativeClause(reboundLetClause);
});
}
}
// If we have any WHERE clauses, we need to add these.
if (bodyAnalysisContext.getWhereClauses() != null) {
for (WhereClause whereClause : bodyAnalysisContext.getWhereClauses()) {
WhereClause copiedClause = (WhereClause) remapCloneVisitor.substitute(whereClause);
loweringEnvironment.acceptTransformer(lowerList -> {
WhereClause newWhereClause = new WhereClause(copiedClause.getWhereExpr());
newWhereClause.setSourceLocation(whereClause.getSourceLocation());
lowerList.addNonRepresentativeClause(newWhereClause);
});
}
}
}