Search in sources :

Example 76 with Expression

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

the class AQLAstPrintVisitor method visit.

@Override
public Void visit(UnionExpr u, Integer step) throws CompilationException {
    out.println(skip(step) + "Union [");
    for (Expression expr : u.getExprs()) {
        expr.accept(this, step + 1);
    }
    out.println(skip(step) + "]");
    return null;
}
Also used : Expression(org.apache.asterix.lang.common.base.Expression) FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression)

Example 77 with Expression

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

the class AQLCloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(UnionExpr u, VariableSubstitutionEnvironment env) throws CompilationException {
    List<Expression> exprList = VariableCloneAndSubstitutionUtil.visitAndCloneExprList(u.getExprs(), env, this);
    UnionExpr newU = new UnionExpr(exprList);
    return new Pair<ILangExpression, VariableSubstitutionEnvironment>(newU, env);
}
Also used : Expression(org.apache.asterix.lang.common.base.Expression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression) UnionExpr(org.apache.asterix.lang.aql.expression.UnionExpr) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 78 with Expression

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

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

the class AqlQueryRewriter method wrapInLets.

private void wrapInLets() {
    // it into a let clause.
    if (topStatement == null) {
        return;
    }
    Expression body = topStatement.getBody();
    if (body.getKind() != Kind.FLWOGR_EXPRESSION) {
        VarIdentifier var = context.newVariable();
        VariableExpr v = new VariableExpr(var);
        LetClause c1 = new LetClause(v, body);
        ArrayList<Clause> clauseList = new ArrayList<>(1);
        clauseList.add(c1);
        FLWOGRExpression newBody = new FLWOGRExpression(clauseList, new VariableExpr(var));
        topStatement.setBody(newBody);
    }
}
Also used : LetClause(org.apache.asterix.lang.common.clause.LetClause) FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression) Expression(org.apache.asterix.lang.common.base.Expression) VarIdentifier(org.apache.asterix.lang.common.struct.VarIdentifier) ArrayList(java.util.ArrayList) FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression) 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)

Example 80 with Expression

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

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