Search in sources :

Example 11 with VariableExpr

use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.

the class AbstractSqlppExpressionScopingVisitor method visit.

@Override
public Expression visit(NestClause nestClause, ILangExpression arg) throws CompilationException {
    // NOTE: the two branches of a NEST cannot be correlated, instead of
    // checking the correlation here, we defer the check to the query
    // optimizer.
    nestClause.setRightExpression(visit(nestClause.getRightExpression(), nestClause));
    // Registers the data item variable.
    VariableExpr rightVar = nestClause.getRightVariable();
    addNewVarSymbolToScope(scopeChecker.getCurrentScope(), rightVar.getVar());
    if (nestClause.hasPositionalVariable()) {
        // Registers the positional variable.
        VariableExpr posVar = nestClause.getPositionalVariable();
        addNewVarSymbolToScope(scopeChecker.getCurrentScope(), posVar.getVar());
    }
    // The condition expression can refer to the just registered variables
    // for the right branch.
    nestClause.setConditionExpression(visit(nestClause.getConditionExpression(), nestClause));
    return null;
}
Also used : VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr)

Example 12 with VariableExpr

use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.

the class AbstractSqlppExpressionScopingVisitor method visit.

@Override
public Expression visit(JoinClause joinClause, ILangExpression arg) throws CompilationException {
    Scope leftScope = scopeChecker.removeCurrentScope();
    scopeChecker.createNewScope();
    // NOTE: the two join branches cannot be correlated, instead of checking
    // the correlation here,
    // we defer the check to the query optimizer.
    joinClause.setRightExpression(visit(joinClause.getRightExpression(), joinClause));
    // Registers the data item variable.
    VariableExpr rightVar = joinClause.getRightVariable();
    addNewVarSymbolToScope(scopeChecker.getCurrentScope(), rightVar.getVar());
    if (joinClause.hasPositionalVariable()) {
        // Registers the positional variable.
        VariableExpr posVar = joinClause.getPositionalVariable();
        addNewVarSymbolToScope(scopeChecker.getCurrentScope(), posVar.getVar());
    }
    Scope rightScope = scopeChecker.removeCurrentScope();
    mergeScopes(leftScope, rightScope);
    scopeChecker.pushExistingScope(leftScope);
    // The condition expression can refer to the just registered variables
    // for the right branch.
    joinClause.setConditionExpression(visit(joinClause.getConditionExpression(), joinClause));
    return null;
}
Also used : Scope(org.apache.asterix.lang.common.context.Scope) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr)

Example 13 with VariableExpr

use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.

the class AbstractSqlppExpressionScopingVisitor method visit.

@Override
public Expression visit(UnnestClause unnestClause, ILangExpression arg) throws CompilationException {
    unnestClause.setRightExpression(visit(unnestClause.getRightExpression(), unnestClause));
    // register the data item variable
    VariableExpr rightVar = unnestClause.getRightVariable();
    addNewVarSymbolToScope(scopeChecker.getCurrentScope(), rightVar.getVar());
    if (unnestClause.hasPositionalVariable()) {
        // register the positional variable
        VariableExpr posVar = unnestClause.getPositionalVariable();
        addNewVarSymbolToScope(scopeChecker.getCurrentScope(), posVar.getVar());
    }
    return null;
}
Also used : VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr)

Example 14 with VariableExpr

use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.

the class SqlppSubstituteExpressionVisitor method preVisit.

// Note: we intentionally override preVisit instead of postVisit because we wants larger expressions
// get substituted first if some of their child expressions are present as keys in the exprMap.
// An example is:
// asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/gby-expr-3/gby-expr-3.3.query.sqlpp
@Override
protected Expression preVisit(Expression expr) throws CompilationException {
    Expression mappedExpr = exprMap.get(expr);
    if (mappedExpr == null) {
        return expr;
    }
    Collection<VariableExpr> freeVars = SqlppVariableUtil.getFreeVariables(expr);
    for (VariableExpr freeVar : freeVars) {
        Scope currentScope = scopeChecker.getCurrentScope();
        if (currentScope.findSymbol(freeVar.getVar().getValue()) != null) {
            // that is being visited, we shouldn't perform the substitution.
            return expr;
        }
    }
    // Makes a deep copy before returning to avoid shared references.
    return (Expression) SqlppRewriteUtil.deepCopy(mappedExpr);
}
Also used : Scope(org.apache.asterix.lang.common.context.Scope) Expression(org.apache.asterix.lang.common.base.Expression) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr)

Example 15 with VariableExpr

use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.

the class VariableCloneAndSubstitutionUtil method substInVarExprPair.

public static List<GbyVariableExpressionPair> substInVarExprPair(LangRewritingContext context, List<GbyVariableExpressionPair> gbyVeList, VariableSubstitutionEnvironment newSubs, CloneAndSubstituteVariablesVisitor visitor) throws CompilationException {
    VariableSubstitutionEnvironment subs = newSubs;
    List<GbyVariableExpressionPair> veList = new LinkedList<>();
    for (GbyVariableExpressionPair vep : gbyVeList) {
        VariableExpr oldGbyVar = vep.getVar();
        VariableExpr newGbyVar = null;
        if (oldGbyVar != null) {
            newGbyVar = visitor.generateNewVariable(context, oldGbyVar);
            subs = eliminateSubstFromList(newGbyVar, subs);
        }
        Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = vep.getExpr().accept(visitor, subs);
        GbyVariableExpressionPair ve2 = new GbyVariableExpressionPair(newGbyVar, (Expression) p1.first);
        veList.add(ve2);
    }
    return veList;
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) LinkedList(java.util.LinkedList)

Aggregations

VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)59 Expression (org.apache.asterix.lang.common.base.Expression)35 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)29 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)20 ArrayList (java.util.ArrayList)19 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)18 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)17 Pair (org.apache.hyracks.algebricks.common.utils.Pair)16 VarIdentifier (org.apache.asterix.lang.common.struct.VarIdentifier)13 CaseExpression (org.apache.asterix.lang.sqlpp.expression.CaseExpression)12 VariableSubstitutionEnvironment (org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment)11 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)11 HashSet (java.util.HashSet)9 HashMap (java.util.HashMap)8 LetClause (org.apache.asterix.lang.common.clause.LetClause)8 Identifier (org.apache.asterix.lang.common.struct.Identifier)8 ForClause (org.apache.asterix.lang.aql.clause.ForClause)7 GroupbyClause (org.apache.asterix.lang.common.clause.GroupbyClause)7 FromTerm (org.apache.asterix.lang.sqlpp.clause.FromTerm)6 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)6