use of org.apache.hyracks.algebricks.core.algebra.properties.OrderColumn 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.OrderColumn 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.OrderColumn 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.OrderColumn 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.OrderColumn in project asterixdb by apache.
the class SubstituteVariableVisitor method visitAssignOperator.
@Override
public Void visitAssignOperator(AssignOperator op, Pair<LogicalVariable, LogicalVariable> pair) throws AlgebricksException {
List<LogicalVariable> variables = op.getVariables();
int n = variables.size();
for (int i = 0; i < n; i++) {
if (variables.get(i).equals(pair.first)) {
variables.set(i, pair.second);
} else {
op.getExpressions().get(i).getValue().substituteVar(pair.first, pair.second);
}
}
// Substitute variables stored in ordering property
if (op.getExplicitOrderingProperty() != null) {
List<OrderColumn> orderColumns = op.getExplicitOrderingProperty().getOrderColumns();
for (int i = 0; i < orderColumns.size(); i++) {
OrderColumn oc = orderColumns.get(i);
if (oc.getColumn().equals(pair.first)) {
orderColumns.set(i, new OrderColumn(pair.second, oc.getOrder()));
}
}
}
substVarTypes(op, pair);
return null;
}
Aggregations