Search in sources :

Example 6 with ReplicateOperator

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());
            }
        }
    }
}
Also used : Mutable(org.apache.commons.lang3.mutable.Mutable) ReplicateOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.ReplicateOperator) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) MutableInt(org.apache.commons.lang3.mutable.MutableInt) BitSet(java.util.BitSet)

Aggregations

ReplicateOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.ReplicateOperator)6 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)5 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Mutable (org.apache.commons.lang3.mutable.Mutable)3 MutableObject (org.apache.commons.lang3.mutable.MutableObject)3 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)3 IAType (org.apache.asterix.om.types.IAType)2 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)2 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)2 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)2 BitSet (java.util.BitSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 CommitOperator (org.apache.asterix.algebra.operators.CommitOperator)1 AsterixException (org.apache.asterix.common.exceptions.AsterixException)1 DataSource (org.apache.asterix.metadata.declared.DataSource)1 DataSourceIndex (org.apache.asterix.metadata.declared.DataSourceIndex)1