Search in sources :

Example 1 with IRangeMap

use of org.apache.hyracks.dataflow.common.data.partition.range.IRangeMap 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)

Example 2 with IRangeMap

use of org.apache.hyracks.dataflow.common.data.partition.range.IRangeMap in project asterixdb by apache.

the class RangeMapBuilder method parseHint.

public static IRangeMap parseHint(Object hint) throws CompilationException {
    ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
    DataOutput out = abvs.getDataOutput();
    ;
    abvs.reset();
    IParser parser = parserFactory.createParser((String) hint);
    List<Statement> hintStatements = parser.parse();
    if (hintStatements.size() != 1) {
        throw new CompilationException("Only one range statement is allowed for the range hint.");
    }
    // Translate the query into a Range Map
    if (hintStatements.get(0).getKind() != Statement.Kind.QUERY) {
        throw new CompilationException("Not a proper query for the range hint.");
    }
    Query q = (Query) hintStatements.get(0);
    if (q.getBody().getKind() != Kind.LIST_CONSTRUCTOR_EXPRESSION) {
        throw new CompilationException("The range hint must be a list.");
    }
    List<Expression> el = ((ListConstructor) q.getBody()).getExprList();
    int[] offsets = new int[el.size()];
    // Loop over list of literals
    for (int i = 0; i < el.size(); ++i) {
        Expression item = el.get(i);
        if (item.getKind() == Kind.LITERAL_EXPRESSION) {
            parseLiteralToBytes(item, out);
            offsets[i] = abvs.getLength();
        }
    // TODO Add support for composite fields.
    }
    return new RangeMap(1, abvs.getByteArray(), offsets);
}
Also used : DataOutput(java.io.DataOutput) CompilationException(org.apache.asterix.common.exceptions.CompilationException) Query(org.apache.asterix.lang.common.statement.Query) Statement(org.apache.asterix.lang.common.base.Statement) ListConstructor(org.apache.asterix.lang.common.expression.ListConstructor) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IRangeMap(org.apache.hyracks.dataflow.common.data.partition.range.IRangeMap) RangeMap(org.apache.hyracks.dataflow.common.data.partition.range.RangeMap) Expression(org.apache.asterix.lang.common.base.Expression) IParser(org.apache.asterix.lang.common.base.IParser)

Aggregations

IRangeMap (org.apache.hyracks.dataflow.common.data.partition.range.IRangeMap)2 DataOutput (java.io.DataOutput)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 CompilationException (org.apache.asterix.common.exceptions.CompilationException)1 Expression (org.apache.asterix.lang.common.base.Expression)1 IParser (org.apache.asterix.lang.common.base.IParser)1 Statement (org.apache.asterix.lang.common.base.Statement)1 ListConstructor (org.apache.asterix.lang.common.expression.ListConstructor)1 Query (org.apache.asterix.lang.common.statement.Query)1 NotImplementedException (org.apache.hyracks.algebricks.common.exceptions.NotImplementedException)1 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)1 IPhysicalOperator (org.apache.hyracks.algebricks.core.algebra.base.IPhysicalOperator)1 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)1 ExchangeOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.ExchangeOperator)1 BroadcastExchangePOperator (org.apache.hyracks.algebricks.core.algebra.operators.physical.BroadcastExchangePOperator)1 HashPartitionExchangePOperator (org.apache.hyracks.algebricks.core.algebra.operators.physical.HashPartitionExchangePOperator)1 HashPartitionMergeExchangePOperator (org.apache.hyracks.algebricks.core.algebra.operators.physical.HashPartitionMergeExchangePOperator)1