use of org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty in project asterixdb by apache.
the class AbstractPreclusteredGroupByPOperator method computeDeliveredProperties.
// Obs: We don't propagate properties corresponding to decors, since they
// are func. dep. on the group-by variables.
@Override
public void computeDeliveredProperties(ILogicalOperator op, IOptimizationContext context) {
List<ILocalStructuralProperty> propsLocal = new ArrayList<>();
GroupByOperator gby = (GroupByOperator) op;
ILogicalOperator op2 = gby.getInputs().get(0).getValue();
IPhysicalPropertiesVector childProp = op2.getDeliveredPhysicalProperties();
IPartitioningProperty pp = childProp.getPartitioningProperty();
List<ILocalStructuralProperty> childLocals = childProp.getLocalProperties();
if (childLocals == null) {
deliveredProperties = new StructuralPropertiesVector(pp, propsLocal);
return;
}
for (ILocalStructuralProperty lsp : childLocals) {
ILocalStructuralProperty propagatedLsp = getPropagatedProperty(lsp, gby);
if (propagatedLsp != null) {
propsLocal.add(propagatedLsp);
}
}
deliveredProperties = new StructuralPropertiesVector(pp, propsLocal);
}
use of org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty in project asterixdb by apache.
the class EnforceStructuralPropertiesRule method addLocalEnforcers.
private void addLocalEnforcers(AbstractLogicalOperator op, int i, List<ILocalStructuralProperty> localProperties, boolean nestedPlan, IOptimizationContext context) throws AlgebricksException {
if (AlgebricksConfig.DEBUG) {
AlgebricksConfig.ALGEBRICKS_LOGGER.fine(">>>> Adding local enforcers for local props = " + localProperties + "\n");
}
if (localProperties == null || localProperties.isEmpty()) {
return;
}
Mutable<ILogicalOperator> topOp = new MutableObject<>();
topOp.setValue(op.getInputs().get(i).getValue());
LinkedList<LocalOrderProperty> oList = new LinkedList<>();
for (ILocalStructuralProperty prop : localProperties) {
switch(prop.getPropertyType()) {
case LOCAL_ORDER_PROPERTY:
{
oList.add((LocalOrderProperty) prop);
break;
}
case LOCAL_GROUPING_PROPERTY:
{
LocalGroupingProperty g = (LocalGroupingProperty) prop;
Collection<LogicalVariable> vars = (g.getPreferredOrderEnforcer() != null) ? g.getPreferredOrderEnforcer() : g.getColumnSet();
List<OrderColumn> orderColumns = new ArrayList<>();
for (LogicalVariable v : vars) {
OrderColumn oc = new OrderColumn(v, OrderKind.ASC);
orderColumns.add(oc);
}
LocalOrderProperty lop = new LocalOrderProperty(orderColumns);
oList.add(lop);
break;
}
default:
{
throw new IllegalStateException();
}
}
}
if (!oList.isEmpty()) {
topOp = enforceOrderProperties(oList, topOp, nestedPlan, context);
}
op.getInputs().set(i, topOp);
OperatorPropertiesUtil.computeSchemaAndPropertiesRecIfNull((AbstractLogicalOperator) topOp.getValue(), context);
OperatorManipulationUtil.setOperatorMode(op);
printOp((AbstractLogicalOperator) topOp.getValue());
}
use of org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty in project asterixdb by apache.
the class EnforceStructuralPropertiesRule method rewritePre.
@Override
public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
// wait for the physical operators to be set first
if (op.getPhysicalOperator() == null) {
return false;
}
if (context.checkIfInDontApplySet(this, op)) {
return false;
}
List<FunctionalDependency> fds = context.getFDList(op);
if (fds != null && !fds.isEmpty()) {
return false;
}
// These are actually logical constraints, so they could be pre-computed
// somewhere else, too.
physicalOptimizationConfig = context.getPhysicalOptimizationConfig();
AlgebricksConfig.ALGEBRICKS_LOGGER.fine(">>>> Optimizing operator " + op.getPhysicalOperator() + ".\n");
PhysicalOptimizationsUtil.computeFDsAndEquivalenceClasses(op, context);
StructuralPropertiesVector pvector = new StructuralPropertiesVector(new RandomPartitioningProperty(context.getComputationNodeDomain()), new LinkedList<ILocalStructuralProperty>());
boolean changed = physOptimizeOp(opRef, pvector, false, context);
op.computeDeliveredPhysicalProperties(context);
AlgebricksConfig.ALGEBRICKS_LOGGER.finest(">>>> Structural properties for " + op.getPhysicalOperator() + ": " + op.getDeliveredPhysicalProperties() + "\n");
context.addToDontApplySet(this, opRef.getValue());
return changed;
}
use of org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty 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.ILocalStructuralProperty in project asterixdb by apache.
the class FDsAndEquivClassesVisitor method visitGroupByOperator.
@Override
public Void visitGroupByOperator(GroupByOperator op, IOptimizationContext ctx) throws AlgebricksException {
Map<LogicalVariable, EquivalenceClass> equivalenceClasses = new HashMap<LogicalVariable, EquivalenceClass>();
List<FunctionalDependency> functionalDependencies = new ArrayList<FunctionalDependency>();
ctx.putEquivalenceClassMap(op, equivalenceClasses);
ctx.putFDList(op, functionalDependencies);
List<FunctionalDependency> inheritedFDs = new ArrayList<FunctionalDependency>();
for (ILogicalPlan p : op.getNestedPlans()) {
for (Mutable<ILogicalOperator> r : p.getRoots()) {
ILogicalOperator op2 = r.getValue();
equivalenceClasses.putAll(getOrComputeEqClasses(op2, ctx));
inheritedFDs.addAll(getOrComputeFDs(op2, ctx));
}
}
ILogicalOperator op0 = op.getInputs().get(0).getValue();
inheritedFDs.addAll(getOrComputeFDs(op0, ctx));
Map<LogicalVariable, EquivalenceClass> inheritedEcs = getOrComputeEqClasses(op0, ctx);
for (FunctionalDependency inherited : inheritedFDs) {
boolean isCoveredByGbyOrDecorVars = true;
List<LogicalVariable> newHead = new ArrayList<LogicalVariable>(inherited.getHead().size());
for (LogicalVariable v : inherited.getHead()) {
LogicalVariable vnew = getNewGbyVar(op, v);
if (vnew == null) {
vnew = getNewDecorVar(op, v);
if (vnew == null) {
isCoveredByGbyOrDecorVars = false;
}
break;
}
newHead.add(vnew);
}
if (isCoveredByGbyOrDecorVars) {
List<LogicalVariable> newTail = new ArrayList<LogicalVariable>();
for (LogicalVariable v2 : inherited.getTail()) {
LogicalVariable v3 = getNewGbyVar(op, v2);
if (v3 != null) {
newTail.add(v3);
}
}
if (!newTail.isEmpty()) {
FunctionalDependency newFd = new FunctionalDependency(newHead, newTail);
functionalDependencies.add(newFd);
}
}
}
List<LogicalVariable> premiseGby = new LinkedList<LogicalVariable>();
List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> gByList = op.getGroupByList();
for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gByList) {
premiseGby.add(p.first);
}
List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> decorList = op.getDecorList();
LinkedList<LogicalVariable> conclDecor = new LinkedList<LogicalVariable>();
for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : decorList) {
conclDecor.add(GroupByOperator.getDecorVariable(p));
}
if (!conclDecor.isEmpty()) {
functionalDependencies.add(new FunctionalDependency(premiseGby, conclDecor));
}
Set<LogicalVariable> gbySet = new HashSet<LogicalVariable>();
for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gByList) {
ILogicalExpression expr = p.second.getValue();
if (expr.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
VariableReferenceExpression v = (VariableReferenceExpression) expr;
gbySet.add(v.getVariableReference());
}
}
LocalGroupingProperty lgp = new LocalGroupingProperty(gbySet);
ILocalStructuralProperty normalizedLgp = lgp.normalize(inheritedEcs, inheritedFDs);
Set<LogicalVariable> normSet = new ListSet<>();
normalizedLgp.getColumns(normSet);
List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> newGbyList = new ArrayList<>();
boolean changed = false;
for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gByList) {
ILogicalExpression expr = p.second.getValue();
if (expr.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
VariableReferenceExpression varRef = (VariableReferenceExpression) expr;
LogicalVariable v2 = varRef.getVariableReference();
EquivalenceClass ec2 = inheritedEcs.get(v2);
LogicalVariable v3;
if (ec2 != null && !ec2.representativeIsConst()) {
v3 = ec2.getVariableRepresentative();
} else {
v3 = v2;
}
if (normSet.contains(v3)) {
newGbyList.add(p);
} else {
changed = true;
decorList.add(p);
}
} else {
newGbyList.add(p);
}
}
if (changed) {
AlgebricksConfig.ALGEBRICKS_LOGGER.fine(">>>> Group-by list changed from " + GroupByOperator.veListToString(gByList) + " to " + GroupByOperator.veListToString(newGbyList) + ".\n");
}
gByList.clear();
gByList.addAll(newGbyList);
return null;
}
Aggregations