Search in sources :

Example 1 with OperatorType

use of org.apache.asterix.lang.common.struct.OperatorType in project asterixdb by apache.

the class OperatorExpressionVisitor method visit.

@Override
public Expression visit(OperatorExpr operatorExpr, ILangExpression arg) throws CompilationException {
    List<Expression> newExprList = new ArrayList<>();
    for (Expression expr : operatorExpr.getExprList()) {
        newExprList.add(expr.accept(this, operatorExpr));
    }
    operatorExpr.setExprList(newExprList);
    OperatorType opType = operatorExpr.getOpList().get(0);
    switch(opType) {
        // There can only be one LIKE/NOT_LIKE/IN/NOT_IN in an operator expression (according to the grammar).
        case LIKE:
        case NOT_LIKE:
            return processLikeOperator(operatorExpr, opType);
        case IN:
        case NOT_IN:
            return processInOperator(operatorExpr, opType);
        case CONCAT:
            // There can be multiple "||"s in one operator expression (according to the grammar).
            return processConcatOperator(operatorExpr);
        case BETWEEN:
        case NOT_BETWEEN:
            return processBetweenOperator(operatorExpr, opType);
        default:
            break;
    }
    return operatorExpr;
}
Also used : Expression(org.apache.asterix.lang.common.base.Expression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) ArrayList(java.util.ArrayList) OperatorType(org.apache.asterix.lang.common.struct.OperatorType)

Example 2 with OperatorType

use of org.apache.asterix.lang.common.struct.OperatorType in project asterixdb by apache.

the class LangExpressionToPlanTranslator method visit.

@Override
public Pair<ILogicalOperator, LogicalVariable> visit(OperatorExpr op, Mutable<ILogicalOperator> tupSource) throws CompilationException {
    List<OperatorType> ops = op.getOpList();
    int nOps = ops.size();
    if (nOps > 0 && (ops.get(0) == OperatorType.AND || ops.get(0) == OperatorType.OR)) {
        return visitAndOrOperator(op, tupSource);
    }
    List<Expression> exprs = op.getExprList();
    Mutable<ILogicalOperator> topOp = tupSource;
    ILogicalExpression currExpr = null;
    for (int i = 0; i <= nOps; i++) {
        Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(exprs.get(i), topOp);
        topOp = p.second;
        ILogicalExpression e = p.first;
        // now look at the operator
        if (i < nOps) {
            if (OperatorExpr.opIsComparison(ops.get(i))) {
                AbstractFunctionCallExpression c = createComparisonExpression(ops.get(i));
                // chain the operators
                if (i == 0) {
                    c.getArguments().add(new MutableObject<>(e));
                    currExpr = c;
                    if (op.isBroadcastOperand(i)) {
                        BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
                        bcast.setObject(BroadcastSide.LEFT);
                        c.getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
                    }
                } else {
                    ((AbstractFunctionCallExpression) currExpr).getArguments().add(new MutableObject<>(e));
                    c.getArguments().add(new MutableObject<>(currExpr));
                    currExpr = c;
                    if (i == 1 && op.isBroadcastOperand(i)) {
                        BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
                        bcast.setObject(BroadcastSide.RIGHT);
                        c.getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
                    }
                }
            } else {
                AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(ops.get(i));
                if (i == 0) {
                    f.getArguments().add(new MutableObject<>(e));
                    currExpr = f;
                } else {
                    ((AbstractFunctionCallExpression) currExpr).getArguments().add(new MutableObject<>(e));
                    f.getArguments().add(new MutableObject<>(currExpr));
                    currExpr = f;
                }
            }
        } else {
            // don't forget the last expression...
            ((AbstractFunctionCallExpression) currExpr).getArguments().add(new MutableObject<>(e));
            if (i == 1 && op.isBroadcastOperand(i)) {
                BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
                bcast.setObject(BroadcastSide.RIGHT);
                ((AbstractFunctionCallExpression) currExpr).getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
            }
        }
    }
    // Add hints as annotations.
    if (op.hasHints() && (currExpr instanceof AbstractFunctionCallExpression)) {
        AbstractFunctionCallExpression currFuncExpr = (AbstractFunctionCallExpression) currExpr;
        for (IExpressionAnnotation hint : op.getHints()) {
            currFuncExpr.getAnnotations().put(hint, hint);
        }
    }
    LogicalVariable assignedVar = context.newVar();
    AssignOperator a = new AssignOperator(assignedVar, new MutableObject<>(currExpr));
    a.getInputs().add(topOp);
    return new Pair<>(a, assignedVar);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) IExpressionAnnotation(org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) OperatorType(org.apache.asterix.lang.common.struct.OperatorType) 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) BroadcastExpressionAnnotation(org.apache.hyracks.algebricks.core.algebra.expressions.BroadcastExpressionAnnotation) 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 3 with OperatorType

use of org.apache.asterix.lang.common.struct.OperatorType in project asterixdb by apache.

the class LangExpressionToPlanTranslator method visitAndOrOperator.

protected Pair<ILogicalOperator, LogicalVariable> visitAndOrOperator(OperatorExpr op, Mutable<ILogicalOperator> tupSource) throws CompilationException {
    List<OperatorType> ops = op.getOpList();
    int nOps = ops.size();
    List<Expression> exprs = op.getExprList();
    Mutable<ILogicalOperator> topOp = tupSource;
    OperatorType opLogical = ops.get(0);
    AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(opLogical);
    for (int i = 0; i <= nOps; i++) {
        Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(exprs.get(i), topOp);
        topOp = p.second;
        // now look at the operator
        if (i < nOps && ops.get(i) != opLogical) {
            throw new TranslationException("Unexpected operator " + ops.get(i) + " in an OperatorExpr starting with " + opLogical);
        }
        f.getArguments().add(new MutableObject<>(p.first));
    }
    LogicalVariable assignedVar = context.newVar();
    AssignOperator a = new AssignOperator(assignedVar, new MutableObject<>(f));
    a.getInputs().add(topOp);
    return new Pair<>(a, assignedVar);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) OperatorType(org.apache.asterix.lang.common.struct.OperatorType) 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) 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 4 with OperatorType

use of org.apache.asterix.lang.common.struct.OperatorType in project asterixdb by apache.

the class FormatPrintVisitor method visit.

@Override
public Void visit(OperatorExpr operatorExpr, Integer step) throws CompilationException {
    List<Expression> exprList = operatorExpr.getExprList();
    List<OperatorType> opList = operatorExpr.getOpList();
    if (operatorExpr.isCurrentop()) {
        out.print("(");
        exprList.get(0).accept(this, step + 1);
        for (int i = 1; i < exprList.size(); i++) {
            OperatorType opType = opList.get(i - 1);
            ;
            if (i == 1) {
                printHints(operatorExpr.getHints(), step + 1);
            }
            out.print(" " + opType + " ");
            exprList.get(i).accept(this, step + 1);
        }
        out.print(")");
    } else {
        exprList.get(0).accept(this, step);
    }
    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) OperatorType(org.apache.asterix.lang.common.struct.OperatorType)

Aggregations

Expression (org.apache.asterix.lang.common.base.Expression)4 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)4 OperatorType (org.apache.asterix.lang.common.struct.OperatorType)4 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)3 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)2 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)2 Mutable (org.apache.commons.lang3.mutable.Mutable)2 Pair (org.apache.hyracks.algebricks.common.utils.Pair)2 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)2 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)2 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)2 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)2 AggregateFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression)2 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)2 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)2 UnnestingFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression)2 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)2 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)2 ArrayList (java.util.ArrayList)1 TypeExpression (org.apache.asterix.lang.common.expression.TypeExpression)1