Search in sources :

Example 1 with QuantifiedExpression

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

the class AbstractInlineUdfsVisitor method visit.

@Override
public Boolean visit(QuantifiedExpression qe, List<FunctionDecl> arg) throws CompilationException {
    boolean changed = false;
    for (QuantifiedPair t : qe.getQuantifiedList()) {
        Pair<Boolean, Expression> p = inlineUdfsInExpr(t.getExpr(), arg);
        t.setExpr(p.second);
        if (p.first) {
            changed = true;
        }
    }
    Pair<Boolean, Expression> p2 = inlineUdfsInExpr(qe.getSatisfiesExpr(), arg);
    qe.setSatisfiesExpr(p2.second);
    return changed || p2.first;
}
Also used : QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) Expression(org.apache.asterix.lang.common.base.Expression)

Example 2 with QuantifiedExpression

use of org.apache.asterix.lang.common.expression.QuantifiedExpression 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 3 with QuantifiedExpression

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

the class DeepCopyVisitor method visit.

@Override
public QuantifiedExpression visit(QuantifiedExpression qe, Void arg) throws CompilationException {
    List<QuantifiedPair> quantifiedPairs = new ArrayList<>();
    for (QuantifiedPair pair : qe.getQuantifiedList()) {
        Expression expr = (Expression) pair.getExpr().accept(this, arg);
        VariableExpr var = (VariableExpr) pair.getVarExpr().accept(this, arg);
        quantifiedPairs.add(new QuantifiedPair(var, expr));
    }
    Expression condition = (Expression) qe.getSatisfiesExpr().accept(this, arg);
    return new QuantifiedExpression(qe.getQuantifier(), quantifiedPairs, condition);
}
Also used : QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) Expression(org.apache.asterix.lang.common.base.Expression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) ArrayList(java.util.ArrayList) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr)

Example 4 with QuantifiedExpression

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

the class CloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(QuantifiedExpression qe, VariableSubstitutionEnvironment env) throws CompilationException {
    List<QuantifiedPair> oldPairs = qe.getQuantifiedList();
    List<QuantifiedPair> newPairs = new ArrayList<>(oldPairs.size());
    VariableSubstitutionEnvironment newSubs = env;
    for (QuantifiedPair t : oldPairs) {
        VariableExpr newVar = generateNewVariable(context, t.getVarExpr());
        newSubs = VariableCloneAndSubstitutionUtil.eliminateSubstFromList(newVar, newSubs);
        Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = visitUnnesBindingExpression(t.getExpr(), newSubs);
        QuantifiedPair t2 = new QuantifiedPair(newVar, (Expression) p1.first);
        newPairs.add(t2);
    }
    Pair<ILangExpression, VariableSubstitutionEnvironment> p2 = qe.getSatisfiesExpr().accept(this, newSubs);
    QuantifiedExpression qe2 = new QuantifiedExpression(qe.getQuantifier(), newPairs, (Expression) p2.first);
    return new Pair<>(qe2, newSubs);
}
Also used : QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair) VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) ArrayList(java.util.ArrayList) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) 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

ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)4 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)4 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)4 Expression (org.apache.asterix.lang.common.base.Expression)3 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)3 ArrayList (java.util.ArrayList)2 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)1 OperatorExpr (org.apache.asterix.lang.common.expression.OperatorExpr)1 VariableSubstitutionEnvironment (org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment)1 CaseExpression (org.apache.asterix.lang.sqlpp.expression.CaseExpression)1 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)1 Pair (org.apache.hyracks.algebricks.common.utils.Pair)1