use of org.apache.hyracks.algebricks.core.algebra.properties.LocalOrderProperty 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.properties.LocalOrderProperty in project asterixdb by apache.
the class EnforceStructuralPropertiesRule method getOrderColumnsFromGroupingProperties.
private List<OrderColumn> getOrderColumnsFromGroupingProperties(List<ILocalStructuralProperty> reqd, List<ILocalStructuralProperty> dlvd) {
List<OrderColumn> returnedProperties = new ArrayList<>();
List<LogicalVariable> rqdCols = new ArrayList<>();
List<LogicalVariable> dlvdCols = new ArrayList<>();
for (ILocalStructuralProperty r : reqd) {
r.getVariables(rqdCols);
}
for (ILocalStructuralProperty d : dlvd) {
d.getVariables(dlvdCols);
}
int prefix = dlvdCols.size() - 1;
while (prefix >= 0) {
if (!rqdCols.contains(dlvdCols.get(prefix))) {
prefix--;
} else {
break;
}
}
LocalOrderProperty orderProp = (LocalOrderProperty) dlvd.get(0);
List<OrderColumn> orderColumns = orderProp.getOrderColumns();
for (int j = 0; j <= prefix; j++) {
returnedProperties.add(new OrderColumn(orderColumns.get(j).getColumn(), orderColumns.get(j).getOrder()));
}
// maintain other order columns after the required order columns
if (!returnedProperties.isEmpty()) {
for (int j = prefix + 1; j < dlvdCols.size(); j++) {
OrderColumn oc = orderColumns.get(j);
returnedProperties.add(new OrderColumn(oc.getColumn(), oc.getOrder()));
}
}
return returnedProperties;
}
use of org.apache.hyracks.algebricks.core.algebra.properties.LocalOrderProperty in project asterixdb by apache.
the class BTreeSearchPOperator method getRequiredPropertiesForChildren.
@Override
public PhysicalRequirements getRequiredPropertiesForChildren(ILogicalOperator op, IPhysicalPropertiesVector reqdByParent, IOptimizationContext context) {
if (requiresBroadcast) {
// For primary indexes optimizing an equality condition we can reduce the broadcast requirement to hash partitioning.
if (isPrimaryIndex && isEqCondition) {
// If this is a composite primary index, then all of the keys should be provided.
Index searchIndex = ((DataSourceIndex) idx).getIndex();
int numberOfKeyFields = searchIndex.getKeyFieldNames().size();
if (numberOfKeyFields < 2 || (lowKeyVarList.size() == numberOfKeyFields && highKeyVarList.size() == numberOfKeyFields)) {
StructuralPropertiesVector[] pv = new StructuralPropertiesVector[1];
ListSet<LogicalVariable> searchKeyVars = new ListSet<>();
searchKeyVars.addAll(lowKeyVarList);
searchKeyVars.addAll(highKeyVarList);
// Also, add a local sorting property to enforce a sort before the primary-index operator.
List<ILocalStructuralProperty> propsLocal = new ArrayList<>();
List<OrderColumn> orderColumns = new ArrayList<>();
for (LogicalVariable orderVar : searchKeyVars) {
orderColumns.add(new OrderColumn(orderVar, OrderKind.ASC));
}
propsLocal.add(new LocalOrderProperty(orderColumns));
pv[0] = new StructuralPropertiesVector(new UnorderedPartitionedProperty(searchKeyVars, domain), propsLocal);
return new PhysicalRequirements(pv, IPartitioningRequirementsCoordinator.NO_COORDINATION);
}
}
StructuralPropertiesVector[] pv = new StructuralPropertiesVector[1];
pv[0] = new StructuralPropertiesVector(new BroadcastPartitioningProperty(domain), null);
return new PhysicalRequirements(pv, IPartitioningRequirementsCoordinator.NO_COORDINATION);
} else {
return super.getRequiredPropertiesForChildren(op, reqdByParent, context);
}
}
use of org.apache.hyracks.algebricks.core.algebra.properties.LocalOrderProperty in project asterixdb by apache.
the class AbstractPreclusteredGroupByPOperator method getPropagatedProperty.
// Returns the local structure property that is propagated from an input local structure property
// through a pre-clustered GROUP BY physical operator.
private ILocalStructuralProperty getPropagatedProperty(ILocalStructuralProperty lsp, GroupByOperator gby) {
PropertyType propertyType = lsp.getPropertyType();
if (propertyType == PropertyType.LOCAL_GROUPING_PROPERTY) {
// A new grouping property is generated.
return new LocalGroupingProperty(new ListSet<>(gby.getGbyVarList()));
} else {
LocalOrderProperty lop = (LocalOrderProperty) lsp;
List<OrderColumn> orderColumns = new ArrayList<>();
for (OrderColumn oc : lop.getOrderColumns()) {
LogicalVariable v2 = getLhsGbyVar(gby, oc.getColumn());
if (v2 != null) {
orderColumns.add(new OrderColumn(v2, oc.getOrder()));
} else {
break;
}
}
// maintained.
return orderColumns.isEmpty() ? null : new LocalOrderProperty(orderColumns);
}
}
use of org.apache.hyracks.algebricks.core.algebra.properties.LocalOrderProperty in project asterixdb by apache.
the class AbstractStableSortPOperator method computeLocalProperties.
public void computeLocalProperties(ILogicalOperator op) {
OrderOperator ord = (OrderOperator) op;
List<OrderColumn> orderColumns = new ArrayList<OrderColumn>();
for (Pair<IOrder, Mutable<ILogicalExpression>> p : ord.getOrderExpressions()) {
ILogicalExpression expr = p.second.getValue();
if (expr.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
VariableReferenceExpression varRef = (VariableReferenceExpression) expr;
LogicalVariable var = varRef.getVariableReference();
orderColumns.add(new OrderColumn(var, p.first.getKind()));
} else {
throw new IllegalStateException();
}
}
sortColumns = orderColumns.toArray(new OrderColumn[orderColumns.size()]);
orderProp = new LocalOrderProperty(orderColumns);
}
Aggregations