use of org.apache.hyracks.algebricks.core.algebra.operators.logical.ReplicateOperator in project asterixdb by apache.
the class ExtractCommonOperatorsRule method computeClusters.
private void computeClusters(Mutable<ILogicalOperator> parentRef, Mutable<ILogicalOperator> opRef, MutableInt currentClusterId) {
// only replicate or split operator has multiple outputs
int outputIndex = 0;
if (opRef.getValue().getOperatorTag() == LogicalOperatorTag.REPLICATE || opRef.getValue().getOperatorTag() == LogicalOperatorTag.SPLIT) {
ReplicateOperator rop = (ReplicateOperator) opRef.getValue();
List<Mutable<ILogicalOperator>> outputs = rop.getOutputs();
for (outputIndex = 0; outputIndex < outputs.size(); outputIndex++) {
if (outputs.get(outputIndex).equals(parentRef)) {
break;
}
}
}
AbstractLogicalOperator aop = (AbstractLogicalOperator) opRef.getValue();
Pair<int[], int[]> labels = aop.getPhysicalOperator().getInputOutputDependencyLabels(opRef.getValue());
List<Mutable<ILogicalOperator>> inputs = opRef.getValue().getInputs();
for (int i = 0; i < inputs.size(); i++) {
Mutable<ILogicalOperator> inputRef = inputs.get(i);
if (labels.second[outputIndex] == 1 && labels.first[i] == 0) {
// 1 -> 0
if (labels.second.length == 1) {
clusterMap.put(opRef, currentClusterId);
// start a new cluster
MutableInt newClusterId = new MutableInt(++lastUsedClusterId);
computeClusters(opRef, inputRef, newClusterId);
BitSet waitForList = clusterWaitForMap.get(currentClusterId.getValue());
if (waitForList == null) {
waitForList = new BitSet();
clusterWaitForMap.put(currentClusterId.getValue(), waitForList);
}
waitForList.set(newClusterId.getValue());
}
} else {
// 0 -> 0 and 1 -> 1
MutableInt prevClusterId = clusterMap.get(opRef);
if (prevClusterId == null || prevClusterId.getValue().equals(currentClusterId.getValue())) {
clusterMap.put(opRef, currentClusterId);
computeClusters(opRef, inputRef, currentClusterId);
} else {
// merge prevClusterId and currentClusterId: update all the map entries that has currentClusterId to prevClusterId
for (BitSet bs : clusterWaitForMap.values()) {
if (bs.get(currentClusterId.getValue())) {
bs.clear(currentClusterId.getValue());
bs.set(prevClusterId.getValue());
}
}
clusterWaitForMap.remove(currentClusterId.getValue());
currentClusterId.setValue(prevClusterId.getValue());
}
}
}
}
Aggregations