Search in sources :

Example 11 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(ForClause fc, VariableSubstitutionEnvironment env) throws CompilationException {
    Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = fc.getInExpr().accept(this, env);
    VariableExpr varExpr = fc.getVarExpr();
    VariableExpr newVe = generateNewVariable(context, varExpr);
    VariableSubstitutionEnvironment resultEnv = new VariableSubstitutionEnvironment(env);
    resultEnv.removeSubstitution(varExpr);
    VariableExpr newPosVarExpr = null;
    if (fc.hasPosVar()) {
        VariableExpr posVarExpr = fc.getPosVarExpr();
        newPosVarExpr = generateNewVariable(context, posVarExpr);
        resultEnv.removeSubstitution(posVarExpr);
    }
    ForClause newFor = new ForClause(newVe, (Expression) p1.first, newPosVarExpr);
    return new Pair<ILangExpression, VariableSubstitutionEnvironment>(newFor, resultEnv);
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) ForClause(org.apache.asterix.lang.aql.clause.ForClause) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 12 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(RecordConstructor rc, VariableSubstitutionEnvironment env) throws CompilationException {
    List<FieldBinding> oldFbs = rc.getFbList();
    ArrayList<FieldBinding> newFbs = new ArrayList<>(oldFbs.size());
    for (FieldBinding fb : oldFbs) {
        Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = fb.getLeftExpr().accept(this, env);
        Pair<ILangExpression, VariableSubstitutionEnvironment> p2 = fb.getRightExpr().accept(this, env);
        FieldBinding fb2 = new FieldBinding((Expression) p1.first, (Expression) p2.first);
        newFbs.add(fb2);
    }
    RecordConstructor newRc = new RecordConstructor(newFbs);
    return new Pair<>(newRc, env);
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) FieldBinding(org.apache.asterix.lang.common.expression.FieldBinding) ArrayList(java.util.ArrayList) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) RecordConstructor(org.apache.asterix.lang.common.expression.RecordConstructor) 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 13 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(WhereClause wc, VariableSubstitutionEnvironment env) throws CompilationException {
    Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = wc.getWhereExpr().accept(this, env);
    WhereClause newW = new WhereClause((Expression) p1.first);
    return new Pair<>(newW, p1.second);
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) WhereClause(org.apache.asterix.lang.common.clause.WhereClause) 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 14 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(FunctionDecl fd, VariableSubstitutionEnvironment env) throws CompilationException {
    List<VarIdentifier> newList = new ArrayList<>(fd.getParamList().size());
    for (VarIdentifier vi : fd.getParamList()) {
        VariableExpr varExpr = new VariableExpr(vi);
        if (!env.constainsOldVar(varExpr)) {
            throw new CompilationException("Parameter " + vi + " does not appear in the substitution list.");
        }
        Expression newExpr = env.findSubstitution(varExpr);
        if (newExpr.getKind() != Kind.VARIABLE_EXPRESSION) {
            throw new CompilationException("Parameter " + vi + " cannot be substituted by a non-variable expression.");
        }
        newList.add(((VariableExpr) newExpr).getVar());
    }
    Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = fd.getFuncBody().accept(this, env);
    FunctionDecl newF = new FunctionDecl(fd.getSignature(), newList, (Expression) p1.first);
    return new Pair<>(newF, env);
}
Also used : CompilationException(org.apache.asterix.common.exceptions.CompilationException) VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) VarIdentifier(org.apache.asterix.lang.common.struct.VarIdentifier) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) Expression(org.apache.asterix.lang.common.base.Expression) ArrayList(java.util.ArrayList) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) FunctionDecl(org.apache.asterix.lang.common.statement.FunctionDecl) 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 15 with VariableSubstitutionEnvironment

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

the class Scope method getVarSubstitutionEnvironment.

/**
     * @return the variable substituion environment for inlining variable references by its original
     */
public VariableSubstitutionEnvironment getVarSubstitutionEnvironment() {
    VariableSubstitutionEnvironment env = new VariableSubstitutionEnvironment();
    env.addMappings(varExprMap);
    return env;
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment)

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