use of org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag in project asterixdb by apache.
the class AbstractDecorrelationRule method descOrSelfIsScanOrJoin.
protected boolean descOrSelfIsScanOrJoin(ILogicalOperator op2) {
LogicalOperatorTag t = op2.getOperatorTag();
if (isScanOrJoin(t)) {
return true;
}
if (op2.getInputs().size() != 1) {
return false;
}
ILogicalOperator alo = op2.getInputs().get(0).getValue();
if (descOrSelfIsScanOrJoin(alo)) {
return true;
}
return false;
}
use of org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag in project asterixdb by apache.
the class RemoveRedundantVariablesRule method removeRedundantVariables.
private boolean removeRedundantVariables(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
LogicalOperatorTag opTag = op.getOperatorTag();
boolean modified = false;
// Update equivalence class map.
if (opTag == LogicalOperatorTag.ASSIGN) {
AssignOperator assignOp = (AssignOperator) op;
int numVars = assignOp.getVariables().size();
for (int i = 0; i < numVars; i++) {
ILogicalExpression expr = assignOp.getExpressions().get(i).getValue();
if (expr.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
continue;
}
VariableReferenceExpression rhsVarRefExpr = (VariableReferenceExpression) expr;
// Update equivalence class map.
LogicalVariable lhs = assignOp.getVariables().get(i);
LogicalVariable rhs = rhsVarRefExpr.getVariableReference();
updateEquivalenceClassMap(lhs, rhs);
}
}
// Replace variable references with their first representative.
if (opTag == LogicalOperatorTag.PROJECT) {
// The project operator does not use expressions, so we need to replace it's variables manually.
if (replaceProjectVars((ProjectOperator) op)) {
modified = true;
}
} else if (op.getOperatorTag() == LogicalOperatorTag.UNIONALL) {
// Replace redundant variables manually in the UnionAll operator.
if (replaceUnionAllVars((UnionAllOperator) op)) {
modified = true;
}
} else {
if (op.acceptExpressionTransform(substVisitor)) {
modified = true;
}
}
// Perform variable replacement in nested plans.
if (op.hasNestedPlans()) {
AbstractOperatorWithNestedPlans opWithNestedPlan = (AbstractOperatorWithNestedPlans) op;
for (ILogicalPlan nestedPlan : opWithNestedPlan.getNestedPlans()) {
for (Mutable<ILogicalOperator> rootRef : nestedPlan.getRoots()) {
if (removeRedundantVariables(rootRef, context)) {
modified = true;
}
}
}
}
// Deal with re-mapping of variables in group by.
if (opTag == LogicalOperatorTag.GROUP) {
if (handleGroupByVarRemapping((GroupByOperator) op)) {
modified = true;
}
}
if (modified) {
context.computeAndSetTypeEnvironmentForOperator(op);
context.addToDontApplySet(this, op);
}
// in the query plan.
if (opTag == LogicalOperatorTag.DISTRIBUTE_RESULT || opTag == LogicalOperatorTag.SINK) {
equivalentVarsMap.clear();
}
return modified;
}
use of org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag in project asterixdb by apache.
the class MoveFreeVariableOperatorOutOfSubplanRule method producedVariablesCanbePropagated.
// Checks whether there is a variable killing operator in the nested pipeline
private boolean producedVariablesCanbePropagated(ILogicalOperator operator) throws AlgebricksException {
ILogicalOperator currentOperator = operator;
// Makes sure the produced variables by operator are not killed in the nested pipeline below it.
while (!currentOperator.getInputs().isEmpty()) {
LogicalOperatorTag operatorTag = currentOperator.getOperatorTag();
if (operatorTag == LogicalOperatorTag.AGGREGATE || operatorTag == LogicalOperatorTag.RUNNINGAGGREGATE || operatorTag == LogicalOperatorTag.GROUP) {
return false;
}
if (operatorTag == LogicalOperatorTag.PROJECT) {
Set<LogicalVariable> producedVars = new HashSet<>();
VariableUtilities.getProducedVariables(currentOperator, producedVars);
ProjectOperator projectOperator = (ProjectOperator) currentOperator;
if (!projectOperator.getVariables().containsAll(producedVars)) {
return false;
}
}
currentOperator = currentOperator.getInputs().get(0).getValue();
}
return true;
}
use of org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag in project asterixdb by apache.
the class PushSelectDownRule method rewritePre.
@Override
public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (op.getOperatorTag() != LogicalOperatorTag.SELECT) {
return false;
}
Mutable<ILogicalOperator> opRef2 = op.getInputs().get(0);
AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
if (context.checkAndAddToAlreadyCompared(op, op2)) {
return false;
}
LogicalOperatorTag tag2 = op2.getOperatorTag();
if (tag2 == LogicalOperatorTag.INNERJOIN || tag2 == LogicalOperatorTag.LEFTOUTERJOIN || tag2 == LogicalOperatorTag.REPLICATE || tag2 == LogicalOperatorTag.SPLIT) {
return false;
} else {
// not a join
boolean res = propagateSelectionRec(opRef, opRef2);
if (res) {
OperatorPropertiesUtil.typeOpRec(opRef, context);
}
return res;
}
}
Aggregations