Search in sources :

Example 1 with AssignPOperator

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

the class IntroduceRapidFrameFlushProjectAssignRule method changeRule.

private boolean changeRule(AbstractLogicalOperator op) {
    boolean planModified = false;
    for (int i = 0; i < op.getInputs().size(); ++i) {
        AbstractLogicalOperator descendantOp = (AbstractLogicalOperator) op.getInputs().get(i).getValue();
        if (descendantOp.getOperatorTag() == LogicalOperatorTag.PROJECT) {
            ProjectOperator projectOp = (ProjectOperator) descendantOp;
            StreamProjectPOperator physicalOp = (StreamProjectPOperator) projectOp.getPhysicalOperator();
            physicalOp.setRapidFrameFlush(true);
            planModified = true;
        } else if (descendantOp.getOperatorTag() == LogicalOperatorTag.ASSIGN) {
            AssignOperator assignOp = (AssignOperator) descendantOp;
            AssignPOperator physicalOp = (AssignPOperator) assignOp.getPhysicalOperator();
            physicalOp.setRapidFrameFlush(true);
            planModified = true;
        }
        changeRule(descendantOp);
    }
    return planModified;
}
Also used : StreamProjectPOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.StreamProjectPOperator) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ProjectOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) AssignPOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.AssignPOperator)

Example 2 with AssignPOperator

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

the class IntroduceRandomPartitioningFeedComputationRule method rewritePre.

@Override
public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    ILogicalOperator op = opRef.getValue();
    if (!op.getOperatorTag().equals(LogicalOperatorTag.ASSIGN)) {
        return false;
    }
    ILogicalOperator opChild = op.getInputs().get(0).getValue();
    if (!opChild.getOperatorTag().equals(LogicalOperatorTag.DATASOURCESCAN)) {
        return false;
    }
    DataSourceScanOperator scanOp = (DataSourceScanOperator) opChild;
    DataSource dataSource = (DataSource) scanOp.getDataSource();
    if (dataSource.getDatasourceType() != DataSource.Type.FEED) {
        return false;
    }
    final FeedDataSource feedDataSource = (FeedDataSource) dataSource;
    FeedConnection feedConnection = feedDataSource.getFeedConnection();
    if (feedConnection.getAppliedFunctions() == null || feedConnection.getAppliedFunctions().size() == 0) {
        return false;
    }
    ExchangeOperator exchangeOp = new ExchangeOperator();
    INodeDomain domain = new INodeDomain() {

        @Override
        public boolean sameAs(INodeDomain domain) {
            return domain == this;
        }

        @Override
        public Integer cardinality() {
            return feedDataSource.getComputeCardinality();
        }
    };
    exchangeOp.setPhysicalOperator(new RandomPartitionExchangePOperator(domain));
    op.getInputs().get(0).setValue(exchangeOp);
    exchangeOp.getInputs().add(new MutableObject<ILogicalOperator>(scanOp));
    ExecutionMode em = ((AbstractLogicalOperator) scanOp).getExecutionMode();
    exchangeOp.setExecutionMode(em);
    exchangeOp.computeDeliveredPhysicalProperties(context);
    context.computeAndSetTypeEnvironmentForOperator(exchangeOp);
    AssignOperator assignOp = (AssignOperator) opRef.getValue();
    AssignPOperator assignPhyOp = (AssignPOperator) assignOp.getPhysicalOperator();
    assignPhyOp.setCardinalityConstraint(domain.cardinality());
    return true;
}
Also used : AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) FeedConnection(org.apache.asterix.metadata.entities.FeedConnection) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) RandomPartitionExchangePOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.RandomPartitionExchangePOperator) ExchangeOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.ExchangeOperator) INodeDomain(org.apache.hyracks.algebricks.core.algebra.properties.INodeDomain) ExecutionMode(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator.ExecutionMode) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) FeedDataSource(org.apache.asterix.metadata.declared.FeedDataSource) DataSource(org.apache.asterix.metadata.declared.DataSource) FeedDataSource(org.apache.asterix.metadata.declared.FeedDataSource) AssignPOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.AssignPOperator) DataSourceScanOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator)

Example 3 with AssignPOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.physical.AssignPOperator 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)

Aggregations

AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)3 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)3 AssignPOperator (org.apache.hyracks.algebricks.core.algebra.operators.physical.AssignPOperator)3 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)2 ExchangeOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.ExchangeOperator)2 ProjectOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator)2 StreamProjectPOperator (org.apache.hyracks.algebricks.core.algebra.operators.physical.StreamProjectPOperator)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DataSource (org.apache.asterix.metadata.declared.DataSource)1 FeedDataSource (org.apache.asterix.metadata.declared.FeedDataSource)1 FeedConnection (org.apache.asterix.metadata.entities.FeedConnection)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 DataSourceScanOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator)1 ReplicateOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.ReplicateOperator)1