Search in sources :

Example 1 with QuantifiedPair

use of org.apache.asterix.lang.common.struct.QuantifiedPair 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 QuantifiedPair

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

the class LangExpressionToPlanTranslator method visit.

@Override
public Pair<ILogicalOperator, LogicalVariable> visit(QuantifiedExpression qe, Mutable<ILogicalOperator> tupSource) throws CompilationException {
    Mutable<ILogicalOperator> topOp = tupSource;
    ILogicalOperator firstOp = null;
    Mutable<ILogicalOperator> lastOp = null;
    for (QuantifiedPair qt : qe.getQuantifiedList()) {
        Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = langExprToAlgExpression(qt.getExpr(), topOp);
        topOp = eo1.second;
        LogicalVariable uVar = context.newVarFromExpression(qt.getVarExpr());
        ILogicalOperator u = new UnnestOperator(uVar, new MutableObject<>(makeUnnestExpression(eo1.first)));
        if (firstOp == null) {
            firstOp = u;
        }
        if (lastOp != null) {
            u.getInputs().add(lastOp);
        }
        lastOp = new MutableObject<>(u);
    }
    // We make all the unnest correspond. to quantif. vars. sit on top
    // in the hope of enabling joins & other optimiz.
    firstOp.getInputs().add(topOp);
    topOp = lastOp;
    Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = langExprToAlgExpression(qe.getSatisfiesExpr(), topOp);
    AggregateFunctionCallExpression fAgg;
    SelectOperator s;
    if (qe.getQuantifier() == Quantifier.SOME) {
        s = new SelectOperator(new MutableObject<>(eo2.first), false, null);
        s.getInputs().add(eo2.second);
        fAgg = BuiltinFunctions.makeAggregateFunctionExpression(BuiltinFunctions.NON_EMPTY_STREAM, new ArrayList<>());
    } else {
        // EVERY
        List<Mutable<ILogicalExpression>> satExprList = new ArrayList<>(1);
        satExprList.add(new MutableObject<>(eo2.first));
        s = new SelectOperator(new MutableObject<>(new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(AlgebricksBuiltinFunctions.NOT), satExprList)), false, null);
        s.getInputs().add(eo2.second);
        fAgg = BuiltinFunctions.makeAggregateFunctionExpression(BuiltinFunctions.EMPTY_STREAM, new ArrayList<>());
    }
    LogicalVariable qeVar = context.newVar();
    AggregateOperator a = new AggregateOperator(mkSingletonArrayList(qeVar), (List) mkSingletonArrayList(new MutableObject<>(fAgg)));
    a.getInputs().add(new MutableObject<>(s));
    return new Pair<>(a, qeVar);
}
Also used : QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair) LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) AggregateFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList) Mutable(org.apache.commons.lang3.mutable.Mutable) UnnestOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) SelectOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator) AggregateOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator) MutableObject(org.apache.commons.lang3.mutable.MutableObject) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression) 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 QuantifiedPair

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

the class QueryPrintVisitor method visit.

@Override
public Void visit(QuantifiedExpression qe, Integer step) throws CompilationException {
    out.println(skip(step) + "QuantifiedExpression " + qe.getQuantifier() + " [");
    // quantifiedList accept visitor
    for (QuantifiedPair pair : qe.getQuantifiedList()) {
        out.print(skip(step + 1) + "[");
        pair.getVarExpr().accept(this, 0);
        out.println(skip(step + 1) + "In");
        pair.getExpr().accept(this, step + 2);
        out.println(skip(step + 1) + "]");
    }
    out.println(skip(step + 1) + "Satifies [");
    qe.getSatisfiesExpr().accept(this, step + 2);
    // for satifies
    out.println(skip(step + 1) + "]");
    // for quantifiedExpr
    out.println(skip(step) + "]");
    return null;
}
Also used : QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair)

Example 4 with QuantifiedPair

use of org.apache.asterix.lang.common.struct.QuantifiedPair 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)

Example 5 with QuantifiedPair

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

the class FormatPrintVisitor method visit.

@Override
public Void visit(QuantifiedExpression qe, Integer step) throws CompilationException {
    out.print(qe.getQuantifier().toString().toLowerCase() + " ");
    // quantifiedList accept visitor
    int index = 0;
    int size = qe.getQuantifiedList().size();
    for (QuantifiedPair pair : qe.getQuantifiedList()) {
        pair.getVarExpr().accept(this, 0);
        out.print(" in ");
        pair.getExpr().accept(this, step + 2);
        if (++index < size) {
            out.println(COMMA);
        }
    }
    out.print(" satisfies ");
    qe.getSatisfiesExpr().accept(this, step + 2);
    return null;
}
Also used : QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair)

Aggregations

QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)8 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)4 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)4 ArrayList (java.util.ArrayList)3 Expression (org.apache.asterix.lang.common.base.Expression)3 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)3 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)2 Pair (org.apache.hyracks.algebricks.common.utils.Pair)2 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 Mutable (org.apache.commons.lang3.mutable.Mutable)1 MutableObject (org.apache.commons.lang3.mutable.MutableObject)1 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)1 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)1 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)1 AggregateFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression)1 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)1 AggregateOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator)1