Search in sources :

Example 66 with Expression

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

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

the class AbstractInlineUdfsVisitor method visit.

@Override
public Boolean visit(RecordConstructor rc, List<FunctionDecl> arg) throws CompilationException {
    boolean changed = false;
    for (FieldBinding b : rc.getFbList()) {
        Pair<Boolean, Expression> leftExprInlined = inlineUdfsInExpr(b.getLeftExpr(), arg);
        b.setLeftExpr(leftExprInlined.second);
        changed = changed || leftExprInlined.first;
        Pair<Boolean, Expression> rightExprInlined = inlineUdfsInExpr(b.getRightExpr(), arg);
        b.setRightExpr(rightExprInlined.second);
        changed = changed || rightExprInlined.first;
    }
    return changed;
}
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) FieldBinding(org.apache.asterix.lang.common.expression.FieldBinding)

Example 68 with Expression

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

the class AbstractInlineUdfsVisitor method visit.

@Override
public Boolean visit(GroupbyClause gc, List<FunctionDecl> arg) throws CompilationException {
    boolean changed = false;
    for (GbyVariableExpressionPair p : gc.getGbyPairList()) {
        Pair<Boolean, Expression> be = inlineUdfsInExpr(p.getExpr(), arg);
        p.setExpr(be.second);
        if (be.first) {
            changed = true;
        }
    }
    for (GbyVariableExpressionPair p : gc.getDecorPairList()) {
        Pair<Boolean, Expression> be = inlineUdfsInExpr(p.getExpr(), arg);
        p.setExpr(be.second);
        if (be.first) {
            changed = true;
        }
    }
    return changed;
}
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) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)

Example 69 with Expression

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

the class ClauseComparator method extractLetBindingVariables.

// Extracts the variables to be substituted.
private Map<VariableExpr, Expression> extractLetBindingVariables(List<Clause> clauses, GroupbyClause cuttingGbyClause) throws CompilationException {
    Map<VariableExpr, Expression> varExprMap = new HashMap<VariableExpr, Expression>();
    int gbyIndex = clauses.indexOf(cuttingGbyClause);
    for (int i = gbyIndex + 1; i < clauses.size(); i++) {
        Clause cl = clauses.get(i);
        if (cl.getClauseType() == ClauseType.LET_CLAUSE) {
            LetClause letClause = (LetClause) cl;
            // inline let variables one by one iteratively.
            letClause.setBindingExpr((Expression) AQLVariableSubstitutionUtil.substituteVariable(letClause.getBindingExpr(), varExprMap));
            varExprMap.put(letClause.getVarExpr(), letClause.getBindingExpr());
        }
    }
    return varExprMap;
}
Also used : LetClause(org.apache.asterix.lang.common.clause.LetClause) HashMap(java.util.HashMap) FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression) Expression(org.apache.asterix.lang.common.base.Expression) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) ForClause(org.apache.asterix.lang.aql.clause.ForClause) DistinctClause(org.apache.asterix.lang.aql.clause.DistinctClause) GroupbyClause(org.apache.asterix.lang.common.clause.GroupbyClause) LetClause(org.apache.asterix.lang.common.clause.LetClause) Clause(org.apache.asterix.lang.common.base.Clause) WhereClause(org.apache.asterix.lang.common.clause.WhereClause)

Example 70 with Expression

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

the class ClauseComparator method visit.

@Override
public Void visit(LetClause lc, Integer step) throws CompilationException {
    out.print(skip(step) + "with ");
    lc.getVarExpr().accept(this, step + 2);
    out.print(" as ");
    Expression bindingExpr = lc.getBindingExpr();
    bindingExpr.accept(this, step + 2);
    out.println();
    return null;
}
Also used : FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression) Expression(org.apache.asterix.lang.common.base.Expression)

Aggregations

Expression (org.apache.asterix.lang.common.base.Expression)105 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)75 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)52 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)41 ArrayList (java.util.ArrayList)37 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)36 Pair (org.apache.hyracks.algebricks.common.utils.Pair)35 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)32 CaseExpression (org.apache.asterix.lang.sqlpp.expression.CaseExpression)32 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)22 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)19 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)19 FLWOGRExpression (org.apache.asterix.lang.aql.expression.FLWOGRExpression)17 Mutable (org.apache.commons.lang3.mutable.Mutable)17 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)17 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)16 AggregateFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression)16 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)16 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)16 UnnestingFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression)16