Search in sources :

Example 11 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(DistinctClause dc, VariableSubstitutionEnvironment env) throws CompilationException {
    List<Expression> exprList = VariableCloneAndSubstitutionUtil.visitAndCloneExprList(dc.getDistinctByExpr(), env, this);
    DistinctClause dc2 = new DistinctClause(exprList);
    return new Pair<ILangExpression, VariableSubstitutionEnvironment>(dc2, env);
}
Also used : DistinctClause(org.apache.asterix.lang.aql.clause.DistinctClause) Expression(org.apache.asterix.lang.common.base.Expression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 12 with ILangExpression

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

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

the class CloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(CallExpr pf, VariableSubstitutionEnvironment env) throws CompilationException {
    List<Expression> exprList = VariableCloneAndSubstitutionUtil.visitAndCloneExprList(pf.getExprList(), env, this);
    CallExpr f = new CallExpr(pf.getFunctionSignature(), exprList);
    return new Pair<>(f, env);
}
Also used : ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) Expression(org.apache.asterix.lang.common.base.Expression) CallExpr(org.apache.asterix.lang.common.expression.CallExpr) 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 ILangExpression

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

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

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