Search in sources :

Example 16 with Expression

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

the class SqlppListInputFunctionRewriteVisitor method visit.

@Override
public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
    List<Expression> newExprList = new ArrayList<>();
    for (Expression expr : callExpr.getExprList()) {
        newExprList.add(expr.accept(this, arg));
    }
    callExpr.setExprList(newExprList);
    return FunctionMapUtil.normalizedListInputFunctions(callExpr);
}
Also used : Expression(org.apache.asterix.lang.common.base.Expression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) ArrayList(java.util.ArrayList)

Example 17 with Expression

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

the class SubstituteGroupbyExpressionVisitor method visit.

@Override
public Expression visit(SelectBlock selectBlock, ILangExpression arg) throws CompilationException {
    if (selectBlock.hasGroupbyClause()) {
        Map<Expression, Expression> map = new HashMap<>();
        for (GbyVariableExpressionPair gbyKeyPair : selectBlock.getGroupbyClause().getGbyPairList()) {
            Expression gbyKeyExpr = gbyKeyPair.getExpr();
            if (gbyKeyExpr.getKind() != Kind.VARIABLE_EXPRESSION) {
                map.put(gbyKeyExpr, gbyKeyPair.getVar());
            }
        }
        // Creates a substitution visitor.
        SubstituteGroupbyExpressionVisitor visitor = new SubstituteGroupbyExpressionVisitor(context, map);
        // Rewrites LET/HAVING/SELECT clauses.
        if (selectBlock.hasLetClausesAfterGroupby()) {
            for (LetClause letClause : selectBlock.getLetListAfterGroupby()) {
                letClause.accept(this, arg);
            }
        }
        if (selectBlock.hasHavingClause()) {
            selectBlock.getHavingClause().accept(visitor, arg);
        }
        selectBlock.getSelectClause().accept(visitor, arg);
        SelectExpression selectExpression = (SelectExpression) arg;
        // For SET operation queries, the GROUP BY key variables will not substitute ORDER BY nor LIMIT expressions.
        if (!selectExpression.getSelectSetOperation().hasRightInputs()) {
            if (selectExpression.hasOrderby()) {
                selectExpression.getOrderbyClause().accept(visitor, arg);
            }
            if (selectExpression.hasLimit()) {
                selectExpression.getLimitClause().accept(visitor, arg);
            }
        }
    }
    return super.visit(selectBlock, arg);
}
Also used : LetClause(org.apache.asterix.lang.common.clause.LetClause) HashMap(java.util.HashMap) Expression(org.apache.asterix.lang.common.base.Expression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression)

Example 18 with Expression

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

the class GatherFunctionCallsVisitor method visit.

@Override
public Void visit(InsertStatement wc, Void arg) throws CompilationException {
    wc.getQuery().accept(this, arg);
    Expression returnExpression = wc.getReturnExpression();
    if (returnExpression != null) {
        returnExpression.accept(this, arg);
    }
    return null;
}
Also used : TypeReferenceExpression(org.apache.asterix.lang.common.expression.TypeReferenceExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) Expression(org.apache.asterix.lang.common.base.Expression)

Example 19 with Expression

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

the class QueryPrintVisitor method visit.

@Override
public Void visit(GroupbyClause gc, Integer step) throws CompilationException {
    out.println(skip(step) + "Groupby");
    for (GbyVariableExpressionPair pair : gc.getGbyPairList()) {
        if (pair.getVar() != null) {
            pair.getVar().accept(this, step + 1);
            out.println(skip(step + 1) + ":=");
        }
        pair.getExpr().accept(this, step + 1);
    }
    if (gc.hasDecorList()) {
        out.println(skip(step + 1) + "Decor");
        for (GbyVariableExpressionPair pair : gc.getDecorPairList()) {
            if (pair.getVar() != null) {
                pair.getVar().accept(this, step + 1);
                out.println(skip(step + 1) + ":=");
            }
            pair.getExpr().accept(this, step + 1);
        }
    }
    if (gc.hasWithMap()) {
        out.println(skip(step + 1) + "With");
        for (Entry<Expression, VariableExpr> entry : gc.getWithVarMap().entrySet()) {
            Expression key = entry.getKey();
            VariableExpr value = entry.getValue();
            key.accept(this, step + 1);
            if (!key.equals(value)) {
                out.println(skip(step + 1) + "AS");
                value.accept(this, step + 1);
            }
        }
    }
    out.println();
    return null;
}
Also used : TypeReferenceExpression(org.apache.asterix.lang.common.expression.TypeReferenceExpression) TypeExpression(org.apache.asterix.lang.common.expression.TypeExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) Expression(org.apache.asterix.lang.common.base.Expression) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr)

Example 20 with Expression

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

the class QueryPrintVisitor method visit.

@Override
public Void visit(CallExpr pf, Integer step) throws CompilationException {
    out.println(skip(step) + "FunctionCall " + pf.getFunctionSignature().toString() + "[");
    for (Expression expr : pf.getExprList()) {
        expr.accept(this, step + 1);
    }
    out.println(skip(step) + "]");
    return null;
}
Also used : TypeReferenceExpression(org.apache.asterix.lang.common.expression.TypeReferenceExpression) TypeExpression(org.apache.asterix.lang.common.expression.TypeExpression) 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