use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans in project asterixdb by apache.
the class CancelUnnestWithNestedListifyRule method applyRuleDown.
private boolean applyRuleDown(Mutable<ILogicalOperator> opRef, Set<LogicalVariable> varSet, IOptimizationContext context) throws AlgebricksException {
boolean changed = applies(opRef, varSet, context);
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
VariableUtilities.getUsedVariables(op, varSet);
if (op.hasNestedPlans()) {
AbstractOperatorWithNestedPlans aonp = (AbstractOperatorWithNestedPlans) op;
for (ILogicalPlan p : aonp.getNestedPlans()) {
for (Mutable<ILogicalOperator> r : p.getRoots()) {
if (applyRuleDown(r, varSet, context)) {
changed = true;
}
context.addToDontApplySet(this, r.getValue());
}
}
}
for (Mutable<ILogicalOperator> i : op.getInputs()) {
if (applyRuleDown(i, varSet, context)) {
changed = true;
}
context.addToDontApplySet(this, i.getValue());
}
return changed;
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans in project asterixdb by apache.
the class OperatorPropertiesUtil method collectUsedAndProducedVariablesInPath.
/**
* @param op
* , the start operator.
* @param dest
* , the destination operator (a direct/indirect input operator).
* @param usedVars
* , the collection of used variables.
* @param producedVars
* , the collection of produced variables.
* @return if the current operator is on the path from the original start operator to the destination operator.
* @throws AlgebricksException
*/
private static boolean collectUsedAndProducedVariablesInPath(ILogicalOperator op, ILogicalOperator dest, Set<LogicalVariable> usedVars, Set<LogicalVariable> producedVars) throws AlgebricksException {
if (op == dest) {
return true;
}
if (((AbstractLogicalOperator) op).hasNestedPlans()) {
AbstractOperatorWithNestedPlans a = (AbstractOperatorWithNestedPlans) op;
for (ILogicalPlan p : a.getNestedPlans()) {
for (Mutable<ILogicalOperator> r : p.getRoots()) {
if (collectUsedAndProducedVariablesInPath(r.getValue(), dest, usedVars, producedVars)) {
VariableUtilities.getUsedVariables(r.getValue(), usedVars);
VariableUtilities.getProducedVariables(r.getValue(), producedVars);
return true;
}
}
}
}
for (Mutable<ILogicalOperator> childRef : op.getInputs()) {
if (collectUsedAndProducedVariablesInPath(childRef.getValue(), dest, usedVars, producedVars)) {
VariableUtilities.getUsedVariables(op, usedVars);
VariableUtilities.getProducedVariables(op, producedVars);
return true;
}
}
return false;
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans in project asterixdb by apache.
the class OperatorPropertiesUtil method computeSchemaAndPropertiesRecIfNull.
public static void computeSchemaAndPropertiesRecIfNull(AbstractLogicalOperator op, IOptimizationContext context) throws AlgebricksException {
if (op.getSchema() == null) {
for (Mutable<ILogicalOperator> i : op.getInputs()) {
computeSchemaAndPropertiesRecIfNull((AbstractLogicalOperator) i.getValue(), context);
}
if (op.hasNestedPlans()) {
AbstractOperatorWithNestedPlans a = (AbstractOperatorWithNestedPlans) op;
for (ILogicalPlan p : a.getNestedPlans()) {
for (Mutable<ILogicalOperator> r : p.getRoots()) {
computeSchemaAndPropertiesRecIfNull((AbstractLogicalOperator) r.getValue(), context);
}
}
}
op.recomputeSchema();
op.computeDeliveredPhysicalProperties(context);
}
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans in project asterixdb by apache.
the class OperatorPropertiesUtil method getFreeVariablesInSelfOrDesc.
/**
* Adds the free variables of the plan rooted at that operator to the
* collection provided.
*
* @param op
* @param vars
* - The collection to which the free variables will be added.
*/
public static void getFreeVariablesInSelfOrDesc(AbstractLogicalOperator op, Set<LogicalVariable> freeVars) throws AlgebricksException {
HashSet<LogicalVariable> produced = new HashSet<>();
VariableUtilities.getProducedVariables(op, produced);
for (LogicalVariable v : produced) {
freeVars.remove(v);
}
HashSet<LogicalVariable> used = new HashSet<>();
VariableUtilities.getUsedVariables(op, used);
for (LogicalVariable v : used) {
freeVars.add(v);
}
if (op.hasNestedPlans()) {
AbstractOperatorWithNestedPlans s = (AbstractOperatorWithNestedPlans) op;
getFreeVariablesInSubplans(s, freeVars);
}
for (Mutable<ILogicalOperator> i : op.getInputs()) {
getFreeVariablesInSelfOrDesc((AbstractLogicalOperator) i.getValue(), freeVars);
}
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractOperatorWithNestedPlans in project asterixdb by apache.
the class PushAggregateIntoNestedSubplanRule method extractAggFunctionsFromExpression.
/**
* @param exprRef
* @param nspWithAgg
* @param context
* @return a pair whose first member is a boolean which is true iff
* something was changed in the expression tree rooted at expr. The
* second member is the result of transforming expr.
* @throws AlgebricksException
*/
private Pair<Boolean, ILogicalExpression> extractAggFunctionsFromExpression(Mutable<ILogicalExpression> exprRef, Map<LogicalVariable, AbstractOperatorWithNestedPlans> nspWithAgg, Map<ILogicalExpression, ILogicalExpression> aggregateExprToVarExpr, IOptimizationContext context) throws AlgebricksException {
ILogicalExpression expr = exprRef.getValue();
switch(expr.getExpressionTag()) {
case FUNCTION_CALL:
AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expr;
FunctionIdentifier fi = BuiltinFunctions.getAggregateFunction(fce.getFunctionIdentifier());
if (fi != null) {
ILogicalExpression a1 = fce.getArguments().get(0).getValue();
if (a1.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
LogicalVariable argVar = ((VariableReferenceExpression) a1).getVariableReference();
AbstractOperatorWithNestedPlans nspOp = nspWithAgg.get(argVar);
if (nspOp != null) {
if (!aggregateExprToVarExpr.containsKey(expr)) {
LogicalVariable newVar = context.newVar();
AggregateFunctionCallExpression aggFun = BuiltinFunctions.makeAggregateFunctionExpression(fi, fce.getArguments());
rewriteAggregateInNestedSubplan(argVar, nspOp, aggFun, newVar, context);
ILogicalExpression newVarExpr = new VariableReferenceExpression(newVar);
aggregateExprToVarExpr.put(expr, newVarExpr);
return new Pair<>(Boolean.TRUE, newVarExpr);
} else {
ILogicalExpression varExpr = aggregateExprToVarExpr.get(expr);
return new Pair<>(Boolean.TRUE, varExpr);
}
}
}
}
boolean change = false;
for (Mutable<ILogicalExpression> a : fce.getArguments()) {
Pair<Boolean, ILogicalExpression> aggArg = extractAggFunctionsFromExpression(a, nspWithAgg, aggregateExprToVarExpr, context);
if (aggArg.first.booleanValue()) {
a.setValue(aggArg.second);
change = true;
}
}
return new Pair<>(change, fce);
case VARIABLE:
case CONSTANT:
return new Pair<>(Boolean.FALSE, expr);
default:
throw new IllegalArgumentException();
}
}
Aggregations