use of org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator in project asterixdb by apache.
the class EnforceStructuralPropertiesRule method enforceOrderProperties.
private Mutable<ILogicalOperator> enforceOrderProperties(List<LocalOrderProperty> oList, Mutable<ILogicalOperator> topOp, boolean isMicroOp, IOptimizationContext context) throws AlgebricksException {
List<Pair<IOrder, Mutable<ILogicalExpression>>> oe = new LinkedList<>();
for (LocalOrderProperty orderProperty : oList) {
for (OrderColumn oc : orderProperty.getOrderColumns()) {
IOrder ordType = (oc.getOrder() == OrderKind.ASC) ? OrderOperator.ASC_ORDER : OrderOperator.DESC_ORDER;
Pair<IOrder, Mutable<ILogicalExpression>> pair = new Pair<>(ordType, new MutableObject<ILogicalExpression>(new VariableReferenceExpression(oc.getColumn())));
oe.add(pair);
}
}
OrderOperator oo = new OrderOperator(oe);
oo.setExecutionMode(AbstractLogicalOperator.ExecutionMode.LOCAL);
if (isMicroOp) {
oo.setPhysicalOperator(new InMemoryStableSortPOperator());
} else {
oo.setPhysicalOperator(new StableSortPOperator(physicalOptimizationConfig.getMaxFramesExternalSort()));
}
oo.getInputs().add(topOp);
context.computeAndSetTypeEnvironmentForOperator(oo);
if (AlgebricksConfig.DEBUG) {
AlgebricksConfig.ALGEBRICKS_LOGGER.fine(">>>> Added sort enforcer " + oo.getPhysicalOperator() + ".\n");
}
return new MutableObject<ILogicalOperator>(oo);
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator in project asterixdb by apache.
the class PushSortDownRule method rewritePre.
@Override
public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
ILogicalOperator operator = opRef.getValue();
if (operator.getOperatorTag() != LogicalOperatorTag.ORDER) {
return false;
}
// Gets used variables in the sort operator.
OrderOperator orderOperator = (OrderOperator) operator;
List<Pair<IOrder, Mutable<ILogicalExpression>>> orderKeys = orderOperator.getOrderExpressions();
Set<LogicalVariable> orderUsedVars = new HashSet<LogicalVariable>();
for (Pair<IOrder, Mutable<ILogicalExpression>> orderKey : orderKeys) {
orderKey.second.getValue().getUsedVariables(orderUsedVars);
}
Mutable<ILogicalOperator> inputOpRef = orderOperator.getInputs().get(0);
ILogicalOperator inputOperator = inputOpRef.getValue();
// 3. Order-destroying operator like unnest/unnest-map cannot be pushed through.
if (inputOperator.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
return false;
}
Set<LogicalVariable> inputProducedVars = new HashSet<LogicalVariable>();
VariableUtilities.getProducedVariables(inputOperator, inputProducedVars);
// Intersects used variables in the sort and variables produced by inputOperator.
orderUsedVars.retainAll(inputProducedVars);
if (!orderUsedVars.isEmpty()) {
// If the sort uses any variable that is produced by this operator.
return false;
}
// Switches sort and its input operator.
opRef.setValue(inputOperator);
inputOpRef.setValue(inputOperator.getInputs().get(0).getValue());
inputOperator.getInputs().get(0).setValue(orderOperator);
// Re-computes the type environments.
context.computeAndSetTypeEnvironmentForOperator(orderOperator);
context.computeAndSetTypeEnvironmentForOperator(inputOperator);
return true;
}
Aggregations