use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan in project asterixdb by apache.
the class ReinferAllTypesRule method typeOpRec.
private void typeOpRec(Mutable<ILogicalOperator> r, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) r.getValue();
for (Mutable<ILogicalOperator> i : op.getInputs()) {
typeOpRec(i, context);
}
if (op.hasNestedPlans()) {
for (ILogicalPlan p : ((AbstractOperatorWithNestedPlans) op).getNestedPlans()) {
typePlan(p, context);
}
}
context.computeAndSetTypeEnvironmentForOperator(op);
context.addToDontApplySet(this, op);
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan in project asterixdb by apache.
the class PushNestedOrderByUnderPreSortedGroupByRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (op.getOperatorTag() != LogicalOperatorTag.GROUP) {
return false;
}
if (op.getPhysicalOperator() == null) {
return false;
}
AbstractPhysicalOperator pOp = (AbstractPhysicalOperator) op.getPhysicalOperator();
if (pOp.getOperatorTag() != PhysicalOperatorTag.PRE_CLUSTERED_GROUP_BY) {
return false;
}
GroupByOperator gby = (GroupByOperator) op;
ILogicalPlan plan = gby.getNestedPlans().get(0);
AbstractLogicalOperator op1 = (AbstractLogicalOperator) plan.getRoots().get(0).getValue();
if (op1.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
return false;
}
Mutable<ILogicalOperator> opRef2 = op1.getInputs().get(0);
AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue();
if (op2.getOperatorTag() != LogicalOperatorTag.ORDER) {
return false;
}
OrderOperator order1 = (OrderOperator) op2;
if (!isIndependentFromChildren(order1)) {
return false;
}
AbstractPhysicalOperator pOrder1 = (AbstractPhysicalOperator) op2.getPhysicalOperator();
if (pOrder1.getOperatorTag() != PhysicalOperatorTag.STABLE_SORT && pOrder1.getOperatorTag() != PhysicalOperatorTag.IN_MEMORY_STABLE_SORT) {
return false;
}
// StableSortPOperator sort1 = (StableSortPOperator) pOrder1;
AbstractLogicalOperator op3 = (AbstractLogicalOperator) op.getInputs().get(0).getValue();
if (op3.getOperatorTag() != LogicalOperatorTag.ORDER) {
return false;
}
AbstractPhysicalOperator pOp3 = (AbstractPhysicalOperator) op3.getPhysicalOperator();
if (pOp3.getOperatorTag() != PhysicalOperatorTag.STABLE_SORT) {
return false;
}
OrderOperator order2 = (OrderOperator) op3;
StableSortPOperator sort2 = (StableSortPOperator) pOp3;
// int k = 0;
for (Pair<IOrder, Mutable<ILogicalExpression>> oe : order1.getOrderExpressions()) {
order2.getOrderExpressions().add(oe);
// sortColumns[n2 + k] = sort1.getSortColumns()[k];
// ++k;
}
// sort2.setSortColumns(sortColumns);
sort2.computeDeliveredProperties(order2, null);
// remove order1
ILogicalOperator underOrder1 = order1.getInputs().get(0).getValue();
opRef2.setValue(underOrder1);
return true;
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan in project asterixdb by apache.
the class PushSubplanWithAggregateDownThroughProductRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
if (op1.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
return false;
}
SubplanOperator subplan = (SubplanOperator) op1;
if (subplan.getNestedPlans().size() != 1) {
return false;
}
ILogicalPlan p = subplan.getNestedPlans().get(0);
if (p.getRoots().size() != 1) {
return false;
}
Mutable<ILogicalOperator> r = p.getRoots().get(0);
if (((AbstractLogicalOperator) r.getValue()).getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
return false;
}
Set<LogicalVariable> free = new HashSet<LogicalVariable>();
OperatorPropertiesUtil.getFreeVariablesInSubplans(subplan, free);
Mutable<ILogicalOperator> op2Ref = op1.getInputs().get(0);
AbstractLogicalOperator op2 = (AbstractLogicalOperator) op2Ref.getValue();
if (op2.getOperatorTag() != LogicalOperatorTag.INNERJOIN) {
return false;
}
AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op2;
if (!OperatorPropertiesUtil.isAlwaysTrueCond(join.getCondition().getValue())) {
return false;
}
Mutable<ILogicalOperator> b0Ref = op2.getInputs().get(0);
ILogicalOperator b0 = b0Ref.getValue();
List<LogicalVariable> b0Scm = new ArrayList<LogicalVariable>();
VariableUtilities.getLiveVariables(b0, b0Scm);
if (b0Scm.containsAll(free)) {
// push subplan on left branch
op2Ref.setValue(b0);
b0Ref.setValue(op1);
opRef.setValue(op2);
return true;
} else {
Mutable<ILogicalOperator> b1Ref = op2.getInputs().get(1);
ILogicalOperator b1 = b1Ref.getValue();
List<LogicalVariable> b1Scm = new ArrayList<LogicalVariable>();
VariableUtilities.getLiveVariables(b1, b1Scm);
if (b1Scm.containsAll(free)) {
// push subplan on right branch
op2Ref.setValue(b1);
b1Ref.setValue(op1);
opRef.setValue(op2);
return true;
} else {
return false;
}
}
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan in project asterixdb by apache.
the class IsomorphismVariableMappingVisitor method mapVariablesInNestedPlans.
private void mapVariablesInNestedPlans(ILogicalOperator opOrigin, ILogicalOperator arg) throws AlgebricksException {
AbstractOperatorWithNestedPlans op = (AbstractOperatorWithNestedPlans) opOrigin;
AbstractOperatorWithNestedPlans argOp = (AbstractOperatorWithNestedPlans) arg;
List<ILogicalPlan> plans = op.getNestedPlans();
List<ILogicalPlan> plansArg = argOp.getNestedPlans();
if (plans.size() != plansArg.size()) {
return;
}
for (int i = 0; i < plans.size(); i++) {
List<Mutable<ILogicalOperator>> roots = plans.get(i).getRoots();
List<Mutable<ILogicalOperator>> rootsArg = plansArg.get(i).getRoots();
if (roots.size() != rootsArg.size()) {
return;
}
for (int j = 0; j < roots.size(); j++) {
ILogicalOperator topOp1 = roots.get(j).getValue();
ILogicalOperator topOp2 = rootsArg.get(j).getValue();
topOp1.accept(this, topOp2);
}
}
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan in project asterixdb by apache.
the class IsomorphismOperatorVisitor method visitSubplanOperator.
@Override
public Boolean visitSubplanOperator(SubplanOperator op, ILogicalOperator arg) throws AlgebricksException {
AbstractLogicalOperator aop = (AbstractLogicalOperator) arg;
if (aop.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
return Boolean.FALSE;
}
SubplanOperator subplanOpArg = (SubplanOperator) copyAndSubstituteVar(op, arg);
List<ILogicalPlan> plans = op.getNestedPlans();
List<ILogicalPlan> plansArg = subplanOpArg.getNestedPlans();
for (int i = 0; i < plans.size(); i++) {
List<Mutable<ILogicalOperator>> roots = plans.get(i).getRoots();
List<Mutable<ILogicalOperator>> rootsArg = plansArg.get(i).getRoots();
if (roots.size() == rootsArg.size()) {
return Boolean.FALSE;
}
for (int j = 0; j < roots.size(); j++) {
ILogicalOperator topOp1 = roots.get(j).getValue();
ILogicalOperator topOp2 = rootsArg.get(j).getValue();
boolean isomorphic = IsomorphismUtilities.isOperatorIsomorphicPlanSegment(topOp1, topOp2);
if (!isomorphic) {
return Boolean.FALSE;
}
}
}
return Boolean.TRUE;
}
Aggregations