Search in sources :

Example 41 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 42 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 43 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)

Example 44 with Expression

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

the class LangExpressionToPlanTranslator method visit.

@Override
public Pair<ILogicalOperator, LogicalVariable> visit(CallExpr fcall, Mutable<ILogicalOperator> tupSource) throws CompilationException {
    LogicalVariable v = context.newVar();
    FunctionSignature signature = fcall.getFunctionSignature();
    List<Mutable<ILogicalExpression>> args = new ArrayList<>();
    Mutable<ILogicalOperator> topOp = tupSource;
    for (Expression expr : fcall.getExprList()) {
        switch(expr.getKind()) {
            case VARIABLE_EXPRESSION:
                LogicalVariable var = context.getVar(((VariableExpr) expr).getVar().getId());
                args.add(new MutableObject<>(new VariableReferenceExpression(var)));
                break;
            case LITERAL_EXPRESSION:
                LiteralExpr val = (LiteralExpr) expr;
                args.add(new MutableObject<>(new ConstantExpression(new AsterixConstantValue(ConstantHelper.objectFromLiteral(val.getValue())))));
                break;
            default:
                Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(expr, topOp);
                AbstractLogicalOperator o1 = (AbstractLogicalOperator) eo.second.getValue();
                args.add(new MutableObject<>(eo.first));
                if (o1 != null && !(o1.getOperatorTag() == LogicalOperatorTag.ASSIGN && hasOnlyChild(o1, topOp))) {
                    topOp = eo.second;
                }
                break;
        }
    }
    AbstractFunctionCallExpression f;
    if ((f = lookupUserDefinedFunction(signature, args)) == null) {
        f = lookupBuiltinFunction(signature.getName(), signature.getArity(), args);
    }
    if (f == null) {
        throw new CompilationException(" Unknown function " + signature.getName() + "@" + signature.getArity());
    }
    // Put hints into function call expr.
    if (fcall.hasHints()) {
        for (IExpressionAnnotation hint : fcall.getHints()) {
            f.getAnnotations().put(hint, hint);
        }
    }
    AssignOperator op = new AssignOperator(v, new MutableObject<>(f));
    if (topOp != null) {
        op.getInputs().add(topOp);
    }
    return new Pair<>(op, v);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) CompilationException(org.apache.asterix.common.exceptions.CompilationException) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ArrayList(java.util.ArrayList) IExpressionAnnotation(org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) AggregateFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression) Expression(org.apache.asterix.lang.common.base.Expression) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) UnnestingFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) LiteralExpr(org.apache.asterix.lang.common.expression.LiteralExpr) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) 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 45 with Expression

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

the class LangExpressionToPlanTranslator method visit.

@Override
public Pair<ILogicalOperator, LogicalVariable> visit(OrderbyClause oc, Mutable<ILogicalOperator> tupSource) throws CompilationException {
    OrderOperator ord = new OrderOperator();
    Iterator<OrderModifier> modifIter = oc.getModifierList().iterator();
    Mutable<ILogicalOperator> topOp = tupSource;
    for (Expression e : oc.getOrderbyList()) {
        Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(e, topOp);
        OrderModifier m = modifIter.next();
        OrderOperator.IOrder comp = (m == OrderModifier.ASC) ? OrderOperator.ASC_ORDER : OrderOperator.DESC_ORDER;
        ord.getOrderExpressions().add(new Pair<>(comp, new MutableObject<>(p.first)));
        topOp = p.second;
    }
    ord.getInputs().add(topOp);
    if (oc.getNumTuples() > 0) {
        ord.getAnnotations().put(OperatorAnnotations.CARDINALITY, oc.getNumTuples());
    }
    if (oc.getNumFrames() > 0) {
        ord.getAnnotations().put(OperatorAnnotations.MAX_NUMBER_FRAMES, oc.getNumFrames());
    }
    if (oc.getRangeMap() != null) {
        Iterator<OrderModifier> orderModifIter = oc.getModifierList().iterator();
        boolean ascending = (orderModifIter.next() == OrderModifier.ASC);
        RangeMapBuilder.verifyRangeOrder(oc.getRangeMap(), ascending);
        ord.getAnnotations().put(OperatorAnnotations.USE_RANGE_CONNECTOR, oc.getRangeMap());
    }
    return new Pair<>(ord, null);
}
Also used : ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) OrderOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) AggregateFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression) Expression(org.apache.asterix.lang.common.base.Expression) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) UnnestingFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression) OrderModifier(org.apache.asterix.lang.common.clause.OrderbyClause.OrderModifier) MutableObject(org.apache.commons.lang3.mutable.MutableObject) 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

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