Search in sources :

Example 6 with RandomPartitioningProperty

use of org.apache.hyracks.algebricks.core.algebra.properties.RandomPartitioningProperty in project asterixdb by apache.

the class DataSourcePartitioningProvider method getInternalDatasetPartitioningProperty.

private static IPartitioningProperty getInternalDatasetPartitioningProperty(DataSource ds, INodeDomain domain, List<LogicalVariable> scanVariables, Set<LogicalVariable> pvars) {
    IPartitioningProperty pp;
    if (scanVariables.size() < 2) {
        pp = new RandomPartitioningProperty(domain);
    } else {
        pvars.addAll(ds.getPrimaryKeyVariables(scanVariables));
        pp = new UnorderedPartitionedProperty(pvars, domain);
    }
    return pp;
}
Also used : UnorderedPartitionedProperty(org.apache.hyracks.algebricks.core.algebra.properties.UnorderedPartitionedProperty) RandomPartitioningProperty(org.apache.hyracks.algebricks.core.algebra.properties.RandomPartitioningProperty) IPartitioningProperty(org.apache.hyracks.algebricks.core.algebra.properties.IPartitioningProperty)

Example 7 with RandomPartitioningProperty

use of org.apache.hyracks.algebricks.core.algebra.properties.RandomPartitioningProperty in project asterixdb by apache.

the class RandomPartitionExchangePOperator method computeDeliveredProperties.

@Override
public void computeDeliveredProperties(ILogicalOperator op, IOptimizationContext context) {
    AbstractLogicalOperator op2 = (AbstractLogicalOperator) op.getInputs().get(0).getValue();
    this.deliveredProperties = new StructuralPropertiesVector(new RandomPartitioningProperty(domain), op2.getDeliveredPhysicalProperties().getLocalProperties());
}
Also used : StructuralPropertiesVector(org.apache.hyracks.algebricks.core.algebra.properties.StructuralPropertiesVector) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) RandomPartitioningProperty(org.apache.hyracks.algebricks.core.algebra.properties.RandomPartitioningProperty)

Example 8 with RandomPartitioningProperty

use of org.apache.hyracks.algebricks.core.algebra.properties.RandomPartitioningProperty in project asterixdb by apache.

the class EnforceStructuralPropertiesRule method rewritePre.

@Override
public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    // wait for the physical operators to be set first
    if (op.getPhysicalOperator() == null) {
        return false;
    }
    if (context.checkIfInDontApplySet(this, op)) {
        return false;
    }
    List<FunctionalDependency> fds = context.getFDList(op);
    if (fds != null && !fds.isEmpty()) {
        return false;
    }
    // These are actually logical constraints, so they could be pre-computed
    // somewhere else, too.
    physicalOptimizationConfig = context.getPhysicalOptimizationConfig();
    AlgebricksConfig.ALGEBRICKS_LOGGER.fine(">>>> Optimizing operator " + op.getPhysicalOperator() + ".\n");
    PhysicalOptimizationsUtil.computeFDsAndEquivalenceClasses(op, context);
    StructuralPropertiesVector pvector = new StructuralPropertiesVector(new RandomPartitioningProperty(context.getComputationNodeDomain()), new LinkedList<ILocalStructuralProperty>());
    boolean changed = physOptimizeOp(opRef, pvector, false, context);
    op.computeDeliveredPhysicalProperties(context);
    AlgebricksConfig.ALGEBRICKS_LOGGER.finest(">>>> Structural properties for " + op.getPhysicalOperator() + ": " + op.getDeliveredPhysicalProperties() + "\n");
    context.addToDontApplySet(this, opRef.getValue());
    return changed;
}
Also used : StructuralPropertiesVector(org.apache.hyracks.algebricks.core.algebra.properties.StructuralPropertiesVector) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) FunctionalDependency(org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency) RandomPartitioningProperty(org.apache.hyracks.algebricks.core.algebra.properties.RandomPartitioningProperty) ILocalStructuralProperty(org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty)

Example 9 with RandomPartitioningProperty

use of org.apache.hyracks.algebricks.core.algebra.properties.RandomPartitioningProperty in project asterixdb by apache.

the class EnforceStructuralPropertiesRule method addPartitioningEnforcers.

private void addPartitioningEnforcers(ILogicalOperator op, int i, IPartitioningProperty pp, IPhysicalPropertiesVector required, IPhysicalPropertiesVector deliveredByChild, INodeDomain domain, IOptimizationContext context) throws AlgebricksException {
    if (pp != null) {
        IPhysicalOperator pop;
        switch(pp.getPartitioningType()) {
            case UNPARTITIONED:
                {
                    List<OrderColumn> ordCols = computeOrderColumns(deliveredByChild);
                    if (ordCols.isEmpty()) {
                        pop = new RandomMergeExchangePOperator();
                    } else {
                        if (op.getAnnotations().containsKey(OperatorAnnotations.USE_RANGE_CONNECTOR)) {
                            IRangeMap rangeMap = (IRangeMap) op.getAnnotations().get(OperatorAnnotations.USE_RANGE_CONNECTOR);
                            pop = new RangePartitionMergeExchangePOperator(ordCols, domain, rangeMap);
                        } else {
                            OrderColumn[] sortColumns = new OrderColumn[ordCols.size()];
                            sortColumns = ordCols.toArray(sortColumns);
                            pop = new SortMergeExchangePOperator(sortColumns);
                        }
                    }
                    break;
                }
            case UNORDERED_PARTITIONED:
                {
                    List<LogicalVariable> varList = new ArrayList<>(((UnorderedPartitionedProperty) pp).getColumnSet());
                    String hashMergeHint = context.getMetadataProvider().getConfig().get(HASH_MERGE);
                    if (hashMergeHint == null || !hashMergeHint.equalsIgnoreCase(TRUE_CONSTANT)) {
                        pop = new HashPartitionExchangePOperator(varList, domain);
                        break;
                    }
                    List<ILocalStructuralProperty> cldLocals = deliveredByChild.getLocalProperties();
                    List<ILocalStructuralProperty> reqdLocals = required.getLocalProperties();
                    boolean propWasSet = false;
                    pop = null;
                    if (reqdLocals != null && cldLocals != null && allAreOrderProps(cldLocals)) {
                        AbstractLogicalOperator c = (AbstractLogicalOperator) op.getInputs().get(i).getValue();
                        Map<LogicalVariable, EquivalenceClass> ecs = context.getEquivalenceClassMap(c);
                        List<FunctionalDependency> fds = context.getFDList(c);
                        if (PropertiesUtil.matchLocalProperties(reqdLocals, cldLocals, ecs, fds)) {
                            List<OrderColumn> orderColumns = getOrderColumnsFromGroupingProperties(reqdLocals, cldLocals);
                            pop = new HashPartitionMergeExchangePOperator(orderColumns, varList, domain);
                            propWasSet = true;
                        }
                    }
                    if (!propWasSet) {
                        pop = new HashPartitionExchangePOperator(varList, domain);
                    }
                    break;
                }
            case ORDERED_PARTITIONED:
                {
                    pop = new RangePartitionExchangePOperator(((OrderedPartitionedProperty) pp).getOrderColumns(), domain, null);
                    break;
                }
            case BROADCAST:
                {
                    pop = new BroadcastExchangePOperator(domain);
                    break;
                }
            case RANDOM:
                {
                    RandomPartitioningProperty rpp = (RandomPartitioningProperty) pp;
                    INodeDomain nd = rpp.getNodeDomain();
                    pop = new RandomPartitionExchangePOperator(nd);
                    break;
                }
            default:
                {
                    throw new NotImplementedException("Enforcer for " + pp.getPartitioningType() + " partitioning type has not been implemented.");
                }
        }
        Mutable<ILogicalOperator> ci = op.getInputs().get(i);
        ExchangeOperator exchg = new ExchangeOperator();
        exchg.setPhysicalOperator(pop);
        setNewOp(ci, exchg, context);
        exchg.setExecutionMode(AbstractLogicalOperator.ExecutionMode.PARTITIONED);
        OperatorPropertiesUtil.computeSchemaAndPropertiesRecIfNull(exchg, context);
        context.computeAndSetTypeEnvironmentForOperator(exchg);
        if (AlgebricksConfig.DEBUG) {
            AlgebricksConfig.ALGEBRICKS_LOGGER.fine(">>>> Added partitioning enforcer " + exchg.getPhysicalOperator() + ".\n");
            printOp((AbstractLogicalOperator) op);
        }
    }
}
Also used : UnorderedPartitionedProperty(org.apache.hyracks.algebricks.core.algebra.properties.UnorderedPartitionedProperty) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) RandomPartitionExchangePOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.RandomPartitionExchangePOperator) NotImplementedException(org.apache.hyracks.algebricks.common.exceptions.NotImplementedException) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) BroadcastExchangePOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.BroadcastExchangePOperator) INodeDomain(org.apache.hyracks.algebricks.core.algebra.properties.INodeDomain) ExchangeOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.ExchangeOperator) RandomMergeExchangePOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.RandomMergeExchangePOperator) HashPartitionMergeExchangePOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.HashPartitionMergeExchangePOperator) RangePartitionMergeExchangePOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.RangePartitionMergeExchangePOperator) HashPartitionExchangePOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.HashPartitionExchangePOperator) IRangeMap(org.apache.hyracks.dataflow.common.data.partition.range.IRangeMap) IPhysicalOperator(org.apache.hyracks.algebricks.core.algebra.base.IPhysicalOperator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) SortMergeExchangePOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.SortMergeExchangePOperator) RangePartitionExchangePOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.RangePartitionExchangePOperator) RandomPartitioningProperty(org.apache.hyracks.algebricks.core.algebra.properties.RandomPartitioningProperty) IRangeMap(org.apache.hyracks.dataflow.common.data.partition.range.IRangeMap) Map(java.util.Map)

Aggregations

RandomPartitioningProperty (org.apache.hyracks.algebricks.core.algebra.properties.RandomPartitioningProperty)9 StructuralPropertiesVector (org.apache.hyracks.algebricks.core.algebra.properties.StructuralPropertiesVector)6 IPartitioningProperty (org.apache.hyracks.algebricks.core.algebra.properties.IPartitioningProperty)4 UnorderedPartitionedProperty (org.apache.hyracks.algebricks.core.algebra.properties.UnorderedPartitionedProperty)4 NotImplementedException (org.apache.hyracks.algebricks.common.exceptions.NotImplementedException)3 ListSet (org.apache.hyracks.algebricks.common.utils.ListSet)3 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)3 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)3 PhysicalRequirements (org.apache.hyracks.algebricks.core.algebra.properties.PhysicalRequirements)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)2 BroadcastPartitioningProperty (org.apache.hyracks.algebricks.core.algebra.properties.BroadcastPartitioningProperty)2 ILocalStructuralProperty (org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty)2 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)1 Pair (org.apache.hyracks.algebricks.common.utils.Pair)1 EquivalenceClass (org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass)1