Search in sources :

Example 16 with VariableSubstitutionEnvironment

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

the class CloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(IfExpr ifexpr, VariableSubstitutionEnvironment env) throws CompilationException {
    Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = ifexpr.getCondExpr().accept(this, env);
    Pair<ILangExpression, VariableSubstitutionEnvironment> p2 = ifexpr.getThenExpr().accept(this, env);
    Pair<ILangExpression, VariableSubstitutionEnvironment> p3 = ifexpr.getElseExpr().accept(this, env);
    IfExpr i = new IfExpr((Expression) p1.first, (Expression) p2.first, (Expression) p3.first);
    return new Pair<>(i, env);
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) IfExpr(org.apache.asterix.lang.common.expression.IfExpr) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair) QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair)

Example 17 with VariableSubstitutionEnvironment

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

the class CloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(UnaryExpr u, VariableSubstitutionEnvironment env) throws CompilationException {
    Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = u.getExpr().accept(this, env);
    UnaryExpr newU = new UnaryExpr(u.getExprType(), (Expression) p1.first);
    return new Pair<>(newU, env);
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) UnaryExpr(org.apache.asterix.lang.common.expression.UnaryExpr) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair) QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair)

Example 18 with VariableSubstitutionEnvironment

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

the class CloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(LetClause lc, VariableSubstitutionEnvironment env) throws CompilationException {
    Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = lc.getBindingExpr().accept(this, env);
    VariableExpr varExpr = lc.getVarExpr();
    VariableExpr newVe = generateNewVariable(context, varExpr);
    LetClause newLet = new LetClause(newVe, (Expression) p1.first);
    return new Pair<>(newLet, VariableCloneAndSubstitutionUtil.eliminateSubstFromList(lc.getVarExpr(), env));
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) LetClause(org.apache.asterix.lang.common.clause.LetClause) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair) QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair)

Example 19 with VariableSubstitutionEnvironment

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

the class CloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(LimitClause lc, VariableSubstitutionEnvironment env) throws CompilationException {
    Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = lc.getLimitExpr().accept(this, env);
    Pair<ILangExpression, VariableSubstitutionEnvironment> p2;
    Expression lcOffsetExpr = lc.getOffset();
    if (lcOffsetExpr != null) {
        p2 = lcOffsetExpr.accept(this, env);
    } else {
        p2 = new Pair<>(null, null);
    }
    LimitClause c = new LimitClause((Expression) p1.first, (Expression) p2.first);
    return new Pair<>(c, env);
}
Also used : LimitClause(org.apache.asterix.lang.common.clause.LimitClause) VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) Expression(org.apache.asterix.lang.common.base.Expression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair) QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair)

Example 20 with VariableSubstitutionEnvironment

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

the class CloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(Query q, VariableSubstitutionEnvironment env) throws CompilationException {
    Query newQ = new Query(q.isExplain());
    Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = q.getBody().accept(this, env);
    newQ.setBody((Expression) p1.first);
    return new Pair<>(newQ, p1.second);
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) Query(org.apache.asterix.lang.common.statement.Query) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair) QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair)

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