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;
}
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);
}
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;
}
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);
}
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;
}
Aggregations