Search in sources :

Example 1 with OperatorExpr

use of org.apache.asterix.lang.common.expression.OperatorExpr in project asterixdb by apache.

the class OperatorExpressionVisitor method createLessThanExpression.

private Expression createLessThanExpression(Expression lhs, Expression rhs, List<IExpressionAnnotation> hints) throws CompilationException {
    OperatorExpr comparison = new OperatorExpr();
    comparison.addOperand(lhs);
    comparison.addOperand(rhs);
    comparison.addOperator("<=");
    if (hints != null) {
        for (IExpressionAnnotation hint : hints) {
            comparison.addHint(hint);
        }
    }
    return comparison;
}
Also used : OperatorExpr(org.apache.asterix.lang.common.expression.OperatorExpr) IExpressionAnnotation(org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation)

Example 2 with OperatorExpr

use of org.apache.asterix.lang.common.expression.OperatorExpr in project asterixdb by apache.

the class OperatorExpressionVisitor method processBetweenOperator.

private Expression processBetweenOperator(OperatorExpr operatorExpr, OperatorType opType) throws CompilationException {
    // The grammar guarantees that the BETWEEN operator gets exactly three expressions.
    Expression target = operatorExpr.getExprList().get(0);
    Expression left = operatorExpr.getExprList().get(1);
    Expression right = operatorExpr.getExprList().get(2);
    // Creates the expression left <= target.
    Expression leftComparison = createLessThanExpression(left, target, operatorExpr.getHints());
    // Creates the expression target <= right.
    Expression rightComparison = createLessThanExpression(target, right, operatorExpr.getHints());
    OperatorExpr andExpr = new OperatorExpr();
    andExpr.addOperand(leftComparison);
    andExpr.addOperand(rightComparison);
    andExpr.addOperator("and");
    return opType == OperatorType.BETWEEN ? andExpr : new CallExpr(new FunctionSignature(null, "not", 1), new ArrayList<>(Collections.singletonList(andExpr)));
}
Also used : OperatorExpr(org.apache.asterix.lang.common.expression.OperatorExpr) 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) CallExpr(org.apache.asterix.lang.common.expression.CallExpr) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature)

Example 3 with OperatorExpr

use of org.apache.asterix.lang.common.expression.OperatorExpr in project asterixdb by apache.

the class OperatorExpressionVisitor method processInOperator.

private Expression processInOperator(OperatorExpr operatorExpr, OperatorType opType) throws CompilationException {
    VariableExpr bindingVar = new VariableExpr(context.newVariable());
    Expression itemExpr = operatorExpr.getExprList().get(0);
    Expression collectionExpr = operatorExpr.getExprList().get(1);
    OperatorExpr comparison = new OperatorExpr();
    comparison.addOperand(itemExpr);
    comparison.addOperand(bindingVar);
    comparison.setCurrentop(true);
    if (opType == OperatorType.IN) {
        comparison.addOperator("=");
        return new QuantifiedExpression(Quantifier.SOME, new ArrayList<>(Collections.singletonList(new QuantifiedPair(bindingVar, collectionExpr))), comparison);
    } else {
        comparison.addOperator("!=");
        return new QuantifiedExpression(Quantifier.EVERY, new ArrayList<>(Collections.singletonList(new QuantifiedPair(bindingVar, collectionExpr))), comparison);
    }
}
Also used : OperatorExpr(org.apache.asterix.lang.common.expression.OperatorExpr) QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) Expression(org.apache.asterix.lang.common.base.Expression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr)

Example 4 with OperatorExpr

use of org.apache.asterix.lang.common.expression.OperatorExpr in project asterixdb by apache.

the class SqlppBuiltinFunctionRewriteVisitor method normalizeCaseExpr.

// Normalizes WHEN expressions so that it can have correct NULL/MISSING semantics as well
// as type promotion semantics.
private CaseExpression normalizeCaseExpr(CaseExpression caseExpr) throws CompilationException {
    LiteralExpr trueLiteral = new LiteralExpr(TrueLiteral.INSTANCE);
    Expression conditionExpr = caseExpr.getConditionExpr();
    if (trueLiteral.equals(conditionExpr)) {
        return caseExpr;
    }
    List<Expression> normalizedWhenExprs = new ArrayList<>();
    for (Expression expr : caseExpr.getWhenExprs()) {
        OperatorExpr operatorExpr = new OperatorExpr();
        operatorExpr.addOperand((Expression) SqlppRewriteUtil.deepCopy(expr));
        operatorExpr.addOperand(caseExpr.getConditionExpr());
        operatorExpr.addOperator("=");
        normalizedWhenExprs.add(operatorExpr);
    }
    return new CaseExpression(trueLiteral, normalizedWhenExprs, caseExpr.getThenExprs(), caseExpr.getElseExpr());
}
Also used : OperatorExpr(org.apache.asterix.lang.common.expression.OperatorExpr) Expression(org.apache.asterix.lang.common.base.Expression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression) ArrayList(java.util.ArrayList) LiteralExpr(org.apache.asterix.lang.common.expression.LiteralExpr) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression)

Example 5 with OperatorExpr

use of org.apache.asterix.lang.common.expression.OperatorExpr in project asterixdb by apache.

the class CloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(OperatorExpr op, VariableSubstitutionEnvironment env) throws CompilationException {
    List<Expression> oldExprList = op.getExprList();
    List<Expression> exprs = new ArrayList<>(oldExprList.size());
    for (Expression e : oldExprList) {
        Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = e.accept(this, env);
        exprs.add((Expression) p1.first);
    }
    OperatorExpr oe = new OperatorExpr(exprs, op.getExprBroadcastIdx(), op.getOpList(), op.isCurrentop());
    return new Pair<>(oe, env);
}
Also used : OperatorExpr(org.apache.asterix.lang.common.expression.OperatorExpr) VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) 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) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) 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

OperatorExpr (org.apache.asterix.lang.common.expression.OperatorExpr)6 Expression (org.apache.asterix.lang.common.base.Expression)5 ArrayList (java.util.ArrayList)4 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)4 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)3 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)2 FunctionSignature (org.apache.asterix.common.functions.FunctionSignature)1 DistinctClause (org.apache.asterix.lang.aql.clause.DistinctClause)1 ForClause (org.apache.asterix.lang.aql.clause.ForClause)1 FLWOGRExpression (org.apache.asterix.lang.aql.expression.FLWOGRExpression)1 Clause (org.apache.asterix.lang.common.base.Clause)1 GroupbyClause (org.apache.asterix.lang.common.clause.GroupbyClause)1 LetClause (org.apache.asterix.lang.common.clause.LetClause)1 WhereClause (org.apache.asterix.lang.common.clause.WhereClause)1 CallExpr (org.apache.asterix.lang.common.expression.CallExpr)1 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)1 LiteralExpr (org.apache.asterix.lang.common.expression.LiteralExpr)1 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)1 VariableSubstitutionEnvironment (org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment)1 CaseExpression (org.apache.asterix.lang.sqlpp.expression.CaseExpression)1