Search in sources :

Example 26 with VariableSubstitutionEnvironment

use of org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment in project asterixdb by apache.

the class VariableCloneAndSubstitutionUtil method visitAndCloneExprList.

public static List<Expression> visitAndCloneExprList(List<Expression> oldExprList, VariableSubstitutionEnvironment arg, CloneAndSubstituteVariablesVisitor visitor) throws CompilationException {
    List<Expression> exprs = new ArrayList<>(oldExprList.size());
    for (Expression e : oldExprList) {
        Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = e.accept(visitor, arg);
        exprs.add((Expression) p1.first);
    }
    return exprs;
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) Expression(org.apache.asterix.lang.common.base.Expression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) ArrayList(java.util.ArrayList) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression)

Example 27 with VariableSubstitutionEnvironment

use of org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment in project asterixdb by apache.

the class AQLCloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(FLWOGRExpression flwor, VariableSubstitutionEnvironment env) throws CompilationException {
    List<Clause> newClauses = new ArrayList<Clause>(flwor.getClauseList().size());
    VariableSubstitutionEnvironment currentEnv = env;
    for (Clause c : flwor.getClauseList()) {
        Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = c.accept(this, currentEnv);
        currentEnv = p1.second;
        newClauses.add((Clause) p1.first);
    }
    Pair<ILangExpression, VariableSubstitutionEnvironment> p2 = flwor.getReturnExpr().accept(this, currentEnv);
    Expression newReturnExpr = (Expression) p2.first;
    FLWOGRExpression newFlwor = new FLWOGRExpression(newClauses, newReturnExpr);
    return new Pair<ILangExpression, VariableSubstitutionEnvironment>(newFlwor, p2.second);
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) Expression(org.apache.asterix.lang.common.base.Expression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression) ArrayList(java.util.ArrayList) FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) ForClause(org.apache.asterix.lang.aql.clause.ForClause) DistinctClause(org.apache.asterix.lang.aql.clause.DistinctClause) Clause(org.apache.asterix.lang.common.base.Clause) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 28 with VariableSubstitutionEnvironment

use of org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment in project asterixdb by apache.

the class SqlppCloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(IndependentSubquery independentSubquery, VariableSubstitutionEnvironment env) throws CompilationException {
    Pair<ILangExpression, VariableSubstitutionEnvironment> p = independentSubquery.getExpr().accept(this, env);
    IndependentSubquery newSubquery = new IndependentSubquery((Expression) p.first);
    return new Pair<>(newSubquery, p.second);
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) IndependentSubquery(org.apache.asterix.lang.sqlpp.expression.IndependentSubquery) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 29 with VariableSubstitutionEnvironment

use of org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment in project asterixdb by apache.

the class SqlppCloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(SelectBlock selectBlock, VariableSubstitutionEnvironment env) throws CompilationException {
    Pair<ILangExpression, VariableSubstitutionEnvironment> newFrom = null;
    Pair<ILangExpression, VariableSubstitutionEnvironment> newLet;
    Pair<ILangExpression, VariableSubstitutionEnvironment> newWhere = null;
    Pair<ILangExpression, VariableSubstitutionEnvironment> newGroupby = null;
    Pair<ILangExpression, VariableSubstitutionEnvironment> newHaving = null;
    Pair<ILangExpression, VariableSubstitutionEnvironment> newSelect;
    List<LetClause> newLetClauses = new ArrayList<>();
    List<LetClause> newLetClausesAfterGby = new ArrayList<>();
    VariableSubstitutionEnvironment currentEnv = new VariableSubstitutionEnvironment(env);
    if (selectBlock.hasFromClause()) {
        newFrom = selectBlock.getFromClause().accept(this, currentEnv);
        currentEnv = newFrom.second;
    }
    if (selectBlock.hasLetClauses()) {
        for (LetClause letClause : selectBlock.getLetList()) {
            newLet = letClause.accept(this, currentEnv);
            currentEnv = newLet.second;
            newLetClauses.add(letClause);
        }
    }
    if (selectBlock.hasWhereClause()) {
        newWhere = selectBlock.getWhereClause().accept(this, currentEnv);
        currentEnv = newWhere.second;
    }
    if (selectBlock.hasGroupbyClause()) {
        newGroupby = selectBlock.getGroupbyClause().accept(this, currentEnv);
        currentEnv = newGroupby.second;
        if (selectBlock.hasLetClausesAfterGroupby()) {
            for (LetClause letClauseAfterGby : selectBlock.getLetListAfterGroupby()) {
                newLet = letClauseAfterGby.accept(this, currentEnv);
                currentEnv = newLet.second;
                newLetClausesAfterGby.add(letClauseAfterGby);
            }
        }
    }
    if (selectBlock.hasHavingClause()) {
        newHaving = selectBlock.getHavingClause().accept(this, currentEnv);
        currentEnv = newHaving.second;
    }
    newSelect = selectBlock.getSelectClause().accept(this, currentEnv);
    currentEnv = newSelect.second;
    FromClause fromClause = newFrom == null ? null : (FromClause) newFrom.first;
    WhereClause whereClause = newWhere == null ? null : (WhereClause) newWhere.first;
    GroupbyClause groupbyClause = newGroupby == null ? null : (GroupbyClause) newGroupby.first;
    HavingClause havingClause = newHaving == null ? null : (HavingClause) newHaving.first;
    return new Pair<>(new SelectBlock((SelectClause) newSelect.first, fromClause, newLetClauses, whereClause, groupbyClause, newLetClausesAfterGby, havingClause), currentEnv);
}
Also used : SelectClause(org.apache.asterix.lang.sqlpp.clause.SelectClause) LetClause(org.apache.asterix.lang.common.clause.LetClause) ArrayList(java.util.ArrayList) WhereClause(org.apache.asterix.lang.common.clause.WhereClause) VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) GroupbyClause(org.apache.asterix.lang.common.clause.GroupbyClause) SelectBlock(org.apache.asterix.lang.sqlpp.clause.SelectBlock) FromClause(org.apache.asterix.lang.sqlpp.clause.FromClause) HavingClause(org.apache.asterix.lang.sqlpp.clause.HavingClause) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 30 with VariableSubstitutionEnvironment

use of org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment in project asterixdb by apache.

the class SqlppCloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(SelectExpression selectExpression, VariableSubstitutionEnvironment env) throws CompilationException {
    boolean subquery = selectExpression.isSubquery();
    List<LetClause> newLetList = new ArrayList<>();
    SelectSetOperation newSelectSetOperation;
    OrderbyClause newOrderbyClause = null;
    LimitClause newLimitClause = null;
    VariableSubstitutionEnvironment currentEnv = env;
    Pair<ILangExpression, VariableSubstitutionEnvironment> p;
    if (selectExpression.hasLetClauses()) {
        for (LetClause letClause : selectExpression.getLetList()) {
            p = letClause.accept(this, currentEnv);
            newLetList.add(letClause);
            currentEnv = p.second;
        }
    }
    p = selectExpression.getSelectSetOperation().accept(this, env);
    newSelectSetOperation = (SelectSetOperation) p.first;
    currentEnv = p.second;
    if (selectExpression.hasOrderby()) {
        p = selectExpression.getOrderbyClause().accept(this, currentEnv);
        newOrderbyClause = (OrderbyClause) p.first;
        currentEnv = p.second;
    }
    if (selectExpression.hasLimit()) {
        p = selectExpression.getLimitClause().accept(this, currentEnv);
        newLimitClause = (LimitClause) p.first;
        currentEnv = p.second;
    }
    return new Pair<>(new SelectExpression(newLetList, newSelectSetOperation, newOrderbyClause, newLimitClause, subquery), currentEnv);
}
Also used : LimitClause(org.apache.asterix.lang.common.clause.LimitClause) VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) LetClause(org.apache.asterix.lang.common.clause.LetClause) SelectSetOperation(org.apache.asterix.lang.sqlpp.clause.SelectSetOperation) ArrayList(java.util.ArrayList) OrderbyClause(org.apache.asterix.lang.common.clause.OrderbyClause) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Aggregations

VariableSubstitutionEnvironment (org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment)31 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)28 Pair (org.apache.hyracks.algebricks.common.utils.Pair)26 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)15 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)14 ArrayList (java.util.ArrayList)13 Expression (org.apache.asterix.lang.common.base.Expression)12 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)11 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)7 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)6 LetClause (org.apache.asterix.lang.common.clause.LetClause)4 CaseExpression (org.apache.asterix.lang.sqlpp.expression.CaseExpression)4 VarIdentifier (org.apache.asterix.lang.common.struct.VarIdentifier)3 ForClause (org.apache.asterix.lang.aql.clause.ForClause)2 GroupbyClause (org.apache.asterix.lang.common.clause.GroupbyClause)2 LimitClause (org.apache.asterix.lang.common.clause.LimitClause)2 WhereClause (org.apache.asterix.lang.common.clause.WhereClause)2 FunctionDecl (org.apache.asterix.lang.common.statement.FunctionDecl)2 FromClause (org.apache.asterix.lang.sqlpp.clause.FromClause)2 FromTerm (org.apache.asterix.lang.sqlpp.clause.FromTerm)2