Search in sources :

Example 1 with ExecutionMode

use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator.ExecutionMode 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 2 with ExecutionMode

use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator.ExecutionMode in project asterixdb by apache.

the class AbstractIntroduceGroupByCombinerRule method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    if (context.checkIfInDontApplySet(this, op)) {
        return false;
    }
    if (op.getOperatorTag() != LogicalOperatorTag.GROUP) {
        return false;
    }
    GroupByOperator gbyOp = (GroupByOperator) op;
    ExecutionMode executionMode = gbyOp.getExecutionMode();
    if (executionMode != ExecutionMode.PARTITIONED && !(executionMode == ExecutionMode.UNPARTITIONED && gbyOp.isGroupAll())) {
        return false;
    }
    BookkeepingInfo bi = new BookkeepingInfo();
    GroupByOperator newGbyOp = opToPush(gbyOp, bi, context);
    if (newGbyOp == null) {
        return false;
    }
    Set<LogicalVariable> newGbyLiveVars = new ListSet<LogicalVariable>();
    VariableUtilities.getLiveVariables(newGbyOp, newGbyLiveVars);
    for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gbyOp.getDecorList()) {
        List<LogicalVariable> usedDecorVars = new ArrayList<LogicalVariable>();
        // p.second.getValue() should always return a VariableReferenceExpression, hence
        // usedDecorVars should always contain only one variable.
        p.second.getValue().getUsedVariables(usedDecorVars);
        if (!newGbyLiveVars.contains(usedDecorVars.get(0))) {
            // Let the left-hand side of gbyOp's decoration expressions populated through the combiner group-by without
            // any intermediate assignment.
            newGbyOp.addDecorExpression(null, p.second.getValue());
        }
    }
    newGbyOp.setExecutionMode(ExecutionMode.LOCAL);
    Object v = gbyOp.getAnnotations().get(OperatorAnnotations.USE_HASH_GROUP_BY);
    newGbyOp.getAnnotations().put(OperatorAnnotations.USE_HASH_GROUP_BY, v);
    Object v2 = gbyOp.getAnnotations().get(OperatorAnnotations.USE_EXTERNAL_GROUP_BY);
    newGbyOp.getAnnotations().put(OperatorAnnotations.USE_EXTERNAL_GROUP_BY, v2);
    List<LogicalVariable> propagatedVars = new LinkedList<LogicalVariable>();
    VariableUtilities.getProducedVariables(newGbyOp, propagatedVars);
    Set<LogicalVariable> freeVars = new HashSet<LogicalVariable>();
    OperatorPropertiesUtil.getFreeVariablesInSubplans(gbyOp, freeVars);
    for (LogicalVariable var : freeVars) {
        if (!propagatedVars.contains(var)) {
            LogicalVariable newDecorVar = context.newVar();
            newGbyOp.addDecorExpression(newDecorVar, new VariableReferenceExpression(var));
            VariableUtilities.substituteVariables(gbyOp.getNestedPlans().get(0).getRoots().get(0).getValue(), var, newDecorVar, context);
        }
    }
    Mutable<ILogicalOperator> opRef3 = gbyOp.getInputs().get(0);
    opRef3.setValue(newGbyOp);
    typeGby(newGbyOp, context);
    typeGby(gbyOp, context);
    context.addToDontApplySet(this, op);
    return true;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) GroupByOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList) ExecutionMode(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator.ExecutionMode) LinkedList(java.util.LinkedList) Mutable(org.apache.commons.lang3.mutable.Mutable) ListSet(org.apache.hyracks.algebricks.common.utils.ListSet) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) MutableObject(org.apache.commons.lang3.mutable.MutableObject) HashSet(java.util.HashSet)

Example 3 with ExecutionMode

use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator.ExecutionMode 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

ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)3 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)3 ExecutionMode (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator.ExecutionMode)3 ExchangeOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.ExchangeOperator)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)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 ListSet (org.apache.hyracks.algebricks.common.utils.ListSet)1 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)1 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)1 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)1 DataSourceScanOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator)1 GroupByOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator)1 AssignPOperator (org.apache.hyracks.algebricks.core.algebra.operators.physical.AssignPOperator)1 OneToOneExchangePOperator (org.apache.hyracks.algebricks.core.algebra.operators.physical.OneToOneExchangePOperator)1