Search in sources :

Example 26 with Expression

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

the class FormatPrintVisitor method visit.

@Override
public Void visit(OrderbyClause oc, Integer step) throws CompilationException {
    out.print(skip(step) + "order by ");
    List<OrderModifier> mlist = oc.getModifierList();
    List<Expression> list = oc.getOrderbyList();
    int index = 0;
    int size = list.size();
    for (Expression expr : oc.getOrderbyList()) {
        expr.accept(this, step);
        OrderModifier orderModifier = mlist.get(index);
        if (orderModifier != OrderModifier.ASC) {
            out.print(" " + orderModifier.toString().toLowerCase());
        }
        if (++index < size) {
            out.print(COMMA);
        }
    }
    out.println();
    return null;
}
Also used : TypeReferenceExpression(org.apache.asterix.lang.common.expression.TypeReferenceExpression) Expression(org.apache.asterix.lang.common.base.Expression) TypeExpression(org.apache.asterix.lang.common.expression.TypeExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) OrderModifier(org.apache.asterix.lang.common.clause.OrderbyClause.OrderModifier)

Example 27 with Expression

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

the class FormatPrintVisitor method printDelimitedExpressions.

protected void printDelimitedExpressions(List<? extends Expression> exprs, String delimiter, int step) throws CompilationException {
    int index = 0;
    int size = exprs.size();
    for (Expression expr : exprs) {
        expr.accept(this, step);
        if (++index < size) {
            out.print(delimiter);
        }
    }
}
Also used : TypeReferenceExpression(org.apache.asterix.lang.common.expression.TypeReferenceExpression) Expression(org.apache.asterix.lang.common.base.Expression) TypeExpression(org.apache.asterix.lang.common.expression.TypeExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression)

Example 28 with Expression

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

use of org.apache.asterix.lang.common.base.Expression 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 30 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(InsertStatement insert, List<FunctionDecl> arg) throws CompilationException {
    boolean changed = false;
    Expression returnExpression = insert.getReturnExpression();
    if (returnExpression != null) {
        Pair<Boolean, Expression> rewrittenReturnExpr = inlineUdfsInExpr(returnExpression, arg);
        insert.setReturnExpression(rewrittenReturnExpr.second);
        changed |= rewrittenReturnExpr.first;
    }
    Pair<Boolean, Expression> rewrittenBodyExpression = inlineUdfsInExpr(insert.getBody(), arg);
    insert.setBody(rewrittenBodyExpression.second);
    return changed || rewrittenBodyExpression.first;
}
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)

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