Search in sources :

Example 1 with OneToOneExchangePOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.physical.OneToOneExchangePOperator in project asterixdb by apache.

the class RequiredCapacityVisitorTest method testUnPartitionedJoin.

@Test
public void testUnPartitionedJoin() throws AlgebricksException {
    IClusterCapacity clusterCapacity = new ClusterCapacity();
    RequiredCapacityVisitor visitor = makeComputationCapacityVisitor(PARALLELISM, clusterCapacity);
    // Constructs a join query plan.
    InnerJoinOperator join = makeJoinOperator(AbstractLogicalOperator.ExecutionMode.UNPARTITIONED);
    // Left child plan of the join.
    ExchangeOperator leftChildExchange = new ExchangeOperator();
    leftChildExchange.setExecutionMode(AbstractLogicalOperator.ExecutionMode.UNPARTITIONED);
    leftChildExchange.setPhysicalOperator(new OneToOneExchangePOperator());
    InnerJoinOperator leftChild = makeJoinOperator(AbstractLogicalOperator.ExecutionMode.UNPARTITIONED);
    join.getInputs().add(new MutableObject<>(leftChildExchange));
    leftChildExchange.getInputs().add(new MutableObject<>(leftChild));
    EmptyTupleSourceOperator ets = new EmptyTupleSourceOperator();
    ets.setExecutionMode(AbstractLogicalOperator.ExecutionMode.UNPARTITIONED);
    leftChild.getInputs().add(new MutableObject<>(ets));
    leftChild.getInputs().add(new MutableObject<>(ets));
    // Right child plan of the join.
    ExchangeOperator rightChildExchange = new ExchangeOperator();
    rightChildExchange.setExecutionMode(AbstractLogicalOperator.ExecutionMode.UNPARTITIONED);
    rightChildExchange.setPhysicalOperator(new OneToOneExchangePOperator());
    GroupByOperator rightChild = makeGroupByOperator(AbstractLogicalOperator.ExecutionMode.UNPARTITIONED);
    join.getInputs().add(new MutableObject<>(rightChildExchange));
    rightChildExchange.getInputs().add(new MutableObject<>(rightChild));
    rightChild.getInputs().add(new MutableObject<>(ets));
    // Verifies the calculated cluster capacity requirement for the test quer plan.
    join.accept(visitor, null);
    Assert.assertTrue(clusterCapacity.getAggregatedCores() == 1);
    Assert.assertTrue(clusterCapacity.getAggregatedMemoryByteSize() == 3 * MEMORY_BUDGET + 5L * FRAME_SIZE);
}
Also used : IClusterCapacity(org.apache.hyracks.api.job.resource.IClusterCapacity) GroupByOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator) ClusterCapacity(org.apache.hyracks.api.job.resource.ClusterCapacity) IClusterCapacity(org.apache.hyracks.api.job.resource.IClusterCapacity) OneToOneExchangePOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.OneToOneExchangePOperator) ExchangeOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.ExchangeOperator) InnerJoinOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator) EmptyTupleSourceOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.EmptyTupleSourceOperator) Test(org.junit.Test)

Example 2 with OneToOneExchangePOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.physical.OneToOneExchangePOperator in project asterixdb by apache.

the class RequiredCapacityVisitorTest method testUnPartitionedGroupBy.

@Test
public void testUnPartitionedGroupBy() throws AlgebricksException {
    IClusterCapacity clusterCapacity = new ClusterCapacity();
    RequiredCapacityVisitor visitor = makeComputationCapacityVisitor(PARALLELISM, clusterCapacity);
    // Constructs a parallel group-by query plan.
    GroupByOperator globalGby = makeGroupByOperator(AbstractLogicalOperator.ExecutionMode.UNPARTITIONED);
    ExchangeOperator exchange = new ExchangeOperator();
    exchange.setPhysicalOperator(new OneToOneExchangePOperator());
    exchange.setExecutionMode(AbstractLogicalOperator.ExecutionMode.UNPARTITIONED);
    GroupByOperator localGby = makeGroupByOperator(AbstractLogicalOperator.ExecutionMode.UNPARTITIONED);
    globalGby.getInputs().add(new MutableObject<>(exchange));
    exchange.getInputs().add(new MutableObject<>(localGby));
    // Verifies the calculated cluster capacity requirement for the test quer plan.
    globalGby.accept(visitor, null);
    Assert.assertTrue(clusterCapacity.getAggregatedCores() == 1);
    Assert.assertTrue(clusterCapacity.getAggregatedMemoryByteSize() == 2 * MEMORY_BUDGET + FRAME_SIZE);
}
Also used : IClusterCapacity(org.apache.hyracks.api.job.resource.IClusterCapacity) GroupByOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator) ClusterCapacity(org.apache.hyracks.api.job.resource.ClusterCapacity) IClusterCapacity(org.apache.hyracks.api.job.resource.IClusterCapacity) OneToOneExchangePOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.OneToOneExchangePOperator) ExchangeOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.ExchangeOperator) Test(org.junit.Test)

Example 3 with OneToOneExchangePOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.physical.OneToOneExchangePOperator in project asterixdb by apache.

the class ExtractCommonOperatorsRule method rewriteForOneEquivalentClass.

private boolean rewriteForOneEquivalentClass(List<Mutable<ILogicalOperator>> members, IOptimizationContext context) throws AlgebricksException {
    List<Mutable<ILogicalOperator>> group = new ArrayList<Mutable<ILogicalOperator>>();
    boolean rewritten = false;
    while (members.size() > 0) {
        group.clear();
        Mutable<ILogicalOperator> candidate = members.remove(members.size() - 1);
        group.add(candidate);
        for (int i = members.size() - 1; i >= 0; i--) {
            Mutable<ILogicalOperator> peer = members.get(i);
            if (IsomorphismUtilities.isOperatorIsomorphic(candidate.getValue(), peer.getValue())) {
                group.add(peer);
                members.remove(i);
            }
        }
        boolean[] materializationFlags = computeMaterilizationFlags(group);
        if (group.isEmpty()) {
            continue;
        }
        candidate = group.get(0);
        ReplicateOperator rop = new ReplicateOperator(group.size(), materializationFlags);
        rop.setPhysicalOperator(new ReplicatePOperator());
        Mutable<ILogicalOperator> ropRef = new MutableObject<ILogicalOperator>(rop);
        AbstractLogicalOperator aopCandidate = (AbstractLogicalOperator) candidate.getValue();
        List<Mutable<ILogicalOperator>> originalCandidateParents = childrenToParents.get(candidate);
        rop.setExecutionMode(((AbstractLogicalOperator) candidate.getValue()).getExecutionMode());
        if (aopCandidate.getOperatorTag() == LogicalOperatorTag.EXCHANGE) {
            rop.getInputs().add(candidate);
        } else {
            AbstractLogicalOperator beforeExchange = new ExchangeOperator();
            beforeExchange.setPhysicalOperator(new OneToOneExchangePOperator());
            beforeExchange.setExecutionMode(rop.getExecutionMode());
            Mutable<ILogicalOperator> beforeExchangeRef = new MutableObject<ILogicalOperator>(beforeExchange);
            beforeExchange.getInputs().add(candidate);
            context.computeAndSetTypeEnvironmentForOperator(beforeExchange);
            rop.getInputs().add(beforeExchangeRef);
        }
        context.computeAndSetTypeEnvironmentForOperator(rop);
        for (Mutable<ILogicalOperator> parentRef : originalCandidateParents) {
            AbstractLogicalOperator parent = (AbstractLogicalOperator) parentRef.getValue();
            int index = parent.getInputs().indexOf(candidate);
            if (parent.getOperatorTag() == LogicalOperatorTag.EXCHANGE) {
                parent.getInputs().set(index, ropRef);
                rop.getOutputs().add(parentRef);
            } else {
                AbstractLogicalOperator exchange = new ExchangeOperator();
                exchange.setPhysicalOperator(new OneToOneExchangePOperator());
                exchange.setExecutionMode(rop.getExecutionMode());
                MutableObject<ILogicalOperator> exchangeRef = new MutableObject<ILogicalOperator>(exchange);
                exchange.getInputs().add(ropRef);
                rop.getOutputs().add(exchangeRef);
                context.computeAndSetTypeEnvironmentForOperator(exchange);
                parent.getInputs().set(index, exchangeRef);
                context.computeAndSetTypeEnvironmentForOperator(parent);
            }
        }
        List<LogicalVariable> liveVarsNew = new ArrayList<LogicalVariable>();
        VariableUtilities.getLiveVariables(candidate.getValue(), liveVarsNew);
        ArrayList<Mutable<ILogicalExpression>> assignExprs = new ArrayList<Mutable<ILogicalExpression>>();
        for (LogicalVariable liveVar : liveVarsNew) {
            assignExprs.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(liveVar)));
        }
        for (Mutable<ILogicalOperator> ref : group) {
            if (ref.equals(candidate)) {
                continue;
            }
            ArrayList<LogicalVariable> liveVars = new ArrayList<LogicalVariable>();
            Map<LogicalVariable, LogicalVariable> variableMappingBack = new HashMap<LogicalVariable, LogicalVariable>();
            IsomorphismUtilities.mapVariablesTopDown(ref.getValue(), candidate.getValue(), variableMappingBack);
            for (int i = 0; i < liveVarsNew.size(); i++) {
                liveVars.add(variableMappingBack.get(liveVarsNew.get(i)));
            }
            AbstractLogicalOperator assignOperator = new AssignOperator(liveVars, assignExprs);
            assignOperator.setExecutionMode(rop.getExecutionMode());
            assignOperator.setPhysicalOperator(new AssignPOperator());
            AbstractLogicalOperator projectOperator = new ProjectOperator(liveVars);
            projectOperator.setPhysicalOperator(new StreamProjectPOperator());
            projectOperator.setExecutionMode(rop.getExecutionMode());
            AbstractLogicalOperator exchOp = new ExchangeOperator();
            exchOp.setPhysicalOperator(new OneToOneExchangePOperator());
            exchOp.setExecutionMode(rop.getExecutionMode());
            exchOp.getInputs().add(ropRef);
            MutableObject<ILogicalOperator> exchOpRef = new MutableObject<ILogicalOperator>(exchOp);
            rop.getOutputs().add(exchOpRef);
            assignOperator.getInputs().add(exchOpRef);
            projectOperator.getInputs().add(new MutableObject<ILogicalOperator>(assignOperator));
            // set the types
            context.computeAndSetTypeEnvironmentForOperator(exchOp);
            context.computeAndSetTypeEnvironmentForOperator(assignOperator);
            context.computeAndSetTypeEnvironmentForOperator(projectOperator);
            List<Mutable<ILogicalOperator>> parentOpList = childrenToParents.get(ref);
            for (Mutable<ILogicalOperator> parentOpRef : parentOpList) {
                AbstractLogicalOperator parentOp = (AbstractLogicalOperator) parentOpRef.getValue();
                int index = parentOp.getInputs().indexOf(ref);
                ILogicalOperator childOp = parentOp.getOperatorTag() == LogicalOperatorTag.PROJECT ? assignOperator : projectOperator;
                if (!HeuristicOptimizer.isHyracksOp(parentOp.getPhysicalOperator().getOperatorTag())) {
                    parentOp.getInputs().set(index, new MutableObject<ILogicalOperator>(childOp));
                } else {
                    // If the parent operator is a hyracks operator,
                    // an extra one-to-one exchange is needed.
                    AbstractLogicalOperator exchg = new ExchangeOperator();
                    exchg.setPhysicalOperator(new OneToOneExchangePOperator());
                    exchg.setExecutionMode(childOp.getExecutionMode());
                    exchg.getInputs().add(new MutableObject<ILogicalOperator>(childOp));
                    parentOp.getInputs().set(index, new MutableObject<ILogicalOperator>(exchg));
                    context.computeAndSetTypeEnvironmentForOperator(exchg);
                }
                context.computeAndSetTypeEnvironmentForOperator(parentOp);
            }
        }
        rewritten = true;
    }
    return rewritten;
}
Also used : OneToOneExchangePOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.OneToOneExchangePOperator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExchangeOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.ExchangeOperator) MutableObject(org.apache.commons.lang3.mutable.MutableObject) LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) StreamProjectPOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.StreamProjectPOperator) ReplicateOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.ReplicateOperator) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ProjectOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) AssignPOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.AssignPOperator) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) ReplicatePOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.ReplicatePOperator)

Example 4 with OneToOneExchangePOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.physical.OneToOneExchangePOperator in project asterixdb by apache.

the class IsolateHyracksOperatorsRule method insertOneToOneExchange.

private static final void insertOneToOneExchange(Mutable<ILogicalOperator> i, IOptimizationContext context) throws AlgebricksException {
    ExchangeOperator e = new ExchangeOperator();
    e.setPhysicalOperator(new OneToOneExchangePOperator());
    ILogicalOperator inOp = i.getValue();
    e.getInputs().add(new MutableObject<ILogicalOperator>(inOp));
    i.setValue(e);
    // e.recomputeSchema();
    OperatorPropertiesUtil.computeSchemaAndPropertiesRecIfNull(e, context);
    ExecutionMode em = ((AbstractLogicalOperator) inOp).getExecutionMode();
    e.setExecutionMode(em);
    e.computeDeliveredPhysicalProperties(context);
    context.computeAndSetTypeEnvironmentForOperator(e);
}
Also used : AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) OneToOneExchangePOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.OneToOneExchangePOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ExchangeOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.ExchangeOperator) ExecutionMode(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator.ExecutionMode)

Aggregations

ExchangeOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.ExchangeOperator)4 OneToOneExchangePOperator (org.apache.hyracks.algebricks.core.algebra.operators.physical.OneToOneExchangePOperator)4 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)2 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)2 GroupByOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator)2 ClusterCapacity (org.apache.hyracks.api.job.resource.ClusterCapacity)2 IClusterCapacity (org.apache.hyracks.api.job.resource.IClusterCapacity)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Mutable (org.apache.commons.lang3.mutable.Mutable)1 MutableObject (org.apache.commons.lang3.mutable.MutableObject)1 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)1 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)1 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)1 ExecutionMode (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator.ExecutionMode)1 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)1 EmptyTupleSourceOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.EmptyTupleSourceOperator)1 InnerJoinOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator)1 ProjectOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator)1