use of org.apache.hyracks.algebricks.core.algebra.properties.LocalGroupingProperty 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.LocalGroupingProperty 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.LocalGroupingProperty 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