Search in sources :

Example 41 with ILangExpression

use of org.apache.asterix.lang.common.base.ILangExpression 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 42 with ILangExpression

use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.

the class SqlppCloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(CaseExpression caseExpr, VariableSubstitutionEnvironment env) throws CompilationException {
    Expression conditionExpr = (Expression) caseExpr.getConditionExpr().accept(this, env).first;
    List<Expression> whenExprList = VariableCloneAndSubstitutionUtil.visitAndCloneExprList(caseExpr.getWhenExprs(), env, this);
    List<Expression> thenExprList = VariableCloneAndSubstitutionUtil.visitAndCloneExprList(caseExpr.getThenExprs(), env, this);
    Expression elseExpr = (Expression) caseExpr.getElseExpr().accept(this, env).first;
    CaseExpression newCaseExpr = new CaseExpression(conditionExpr, whenExprList, thenExprList, elseExpr);
    return new Pair<>(newCaseExpr, env);
}
Also used : ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression) Expression(org.apache.asterix.lang.common.base.Expression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 43 with ILangExpression

use of org.apache.asterix.lang.common.base.ILangExpression 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 44 with ILangExpression

use of org.apache.asterix.lang.common.base.ILangExpression 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 45 with ILangExpression

use of org.apache.asterix.lang.common.base.ILangExpression 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

ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)56 Expression (org.apache.asterix.lang.common.base.Expression)34 Pair (org.apache.hyracks.algebricks.common.utils.Pair)34 VariableSubstitutionEnvironment (org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment)28 ArrayList (java.util.ArrayList)23 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)23 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)18 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)18 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)16 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)15 CaseExpression (org.apache.asterix.lang.sqlpp.expression.CaseExpression)9 LetClause (org.apache.asterix.lang.common.clause.LetClause)8 HashMap (java.util.HashMap)5 VarIdentifier (org.apache.asterix.lang.common.struct.VarIdentifier)5 FunctionSignature (org.apache.asterix.common.functions.FunctionSignature)4 CallExpr (org.apache.asterix.lang.common.expression.CallExpr)4 FromClause (org.apache.asterix.lang.sqlpp.clause.FromClause)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PrintWriter (java.io.PrintWriter)3 FLWOGRExpression (org.apache.asterix.lang.aql.expression.FLWOGRExpression)3