use of org.apache.hyracks.algebricks.core.algebra.operators.physical.AbstractStableSortPOperator in project asterixdb by apache.
the class EnforceStructuralPropertiesRule method isRedundantSort.
/*
* We assume delivered to be already normalized.
*/
private boolean isRedundantSort(Mutable<ILogicalOperator> opRef, IPhysicalPropertiesVector delivered, IPhysicalPropertiesVector diffOfProperties, IOptimizationContext context) {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (op.getOperatorTag() != LogicalOperatorTag.ORDER || (op.getPhysicalOperator().getOperatorTag() != PhysicalOperatorTag.STABLE_SORT && op.getPhysicalOperator().getOperatorTag() != PhysicalOperatorTag.IN_MEMORY_STABLE_SORT) || delivered.getLocalProperties() == null) {
return false;
}
AbstractStableSortPOperator sortOp = (AbstractStableSortPOperator) op.getPhysicalOperator();
sortOp.computeLocalProperties(op);
ILocalStructuralProperty orderProp = sortOp.getOrderProperty();
return PropertiesUtil.matchLocalProperties(Collections.singletonList(orderProp), delivered.getLocalProperties(), context.getEquivalenceClassMap(op), context.getFDList(op));
}
use of org.apache.hyracks.algebricks.core.algebra.operators.physical.AbstractStableSortPOperator in project asterixdb by apache.
the class PushGroupByIntoSortRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
ILogicalOperator op1 = opRef.getValue();
if (op1 == null) {
return false;
}
boolean changed = false;
for (Mutable<ILogicalOperator> childRef : op1.getInputs()) {
AbstractLogicalOperator op = (AbstractLogicalOperator) childRef.getValue();
if (op.getOperatorTag() == LogicalOperatorTag.GROUP) {
PhysicalOperatorTag opTag = op.getPhysicalOperator().getOperatorTag();
GroupByOperator groupByOperator = (GroupByOperator) op;
if (opTag == PhysicalOperatorTag.PRE_CLUSTERED_GROUP_BY) {
Mutable<ILogicalOperator> op2Ref = op.getInputs().get(0).getValue().getInputs().get(0);
AbstractLogicalOperator op2 = (AbstractLogicalOperator) op2Ref.getValue();
if (op2.getPhysicalOperator().getOperatorTag() == PhysicalOperatorTag.STABLE_SORT) {
AbstractStableSortPOperator sortPhysicalOperator = (AbstractStableSortPOperator) op2.getPhysicalOperator();
if (groupByOperator.getNestedPlans().size() != 1) {
//an aggregate and a nested-tuple-source.
continue;
}
ILogicalPlan p0 = groupByOperator.getNestedPlans().get(0);
if (p0.getRoots().size() != 1) {
//an aggregate and a nested-tuple-source.
continue;
}
Mutable<ILogicalOperator> r0 = p0.getRoots().get(0);
AbstractLogicalOperator r0Logical = (AbstractLogicalOperator) r0.getValue();
if (r0Logical.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
//we only rewrite aggregation function; do nothing for running aggregates
continue;
}
AggregateOperator aggOp = (AggregateOperator) r0.getValue();
AbstractLogicalOperator aggInputOp = (AbstractLogicalOperator) aggOp.getInputs().get(0).getValue();
if (aggInputOp.getOperatorTag() != LogicalOperatorTag.NESTEDTUPLESOURCE) {
continue;
}
boolean hasIntermediateAggregate = generateMergeAggregationExpressions(groupByOperator, context);
if (!hasIntermediateAggregate) {
continue;
}
//replace preclustered gby with sort gby
if (!groupByOperator.isGroupAll()) {
op.setPhysicalOperator(new SortGroupByPOperator(groupByOperator.getGroupByList(), context.getPhysicalOptimizationConfig().getMaxFramesExternalGroupBy(), sortPhysicalOperator.getSortColumns()));
}
// remove the stable sort operator
op.getInputs().clear();
op.getInputs().addAll(op2.getInputs());
changed = true;
}
}
continue;
} else {
continue;
}
}
return changed;
}
Aggregations