Search in sources :

Example 11 with LocalOrderProperty

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

the class EnforceStructuralPropertiesRule method enforceOrderProperties.

private Mutable<ILogicalOperator> enforceOrderProperties(List<LocalOrderProperty> oList, Mutable<ILogicalOperator> topOp, boolean isMicroOp, IOptimizationContext context) throws AlgebricksException {
    List<Pair<IOrder, Mutable<ILogicalExpression>>> oe = new LinkedList<>();
    for (LocalOrderProperty orderProperty : oList) {
        for (OrderColumn oc : orderProperty.getOrderColumns()) {
            IOrder ordType = (oc.getOrder() == OrderKind.ASC) ? OrderOperator.ASC_ORDER : OrderOperator.DESC_ORDER;
            Pair<IOrder, Mutable<ILogicalExpression>> pair = new Pair<>(ordType, new MutableObject<ILogicalExpression>(new VariableReferenceExpression(oc.getColumn())));
            oe.add(pair);
        }
    }
    OrderOperator oo = new OrderOperator(oe);
    oo.setExecutionMode(AbstractLogicalOperator.ExecutionMode.LOCAL);
    if (isMicroOp) {
        oo.setPhysicalOperator(new InMemoryStableSortPOperator());
    } else {
        oo.setPhysicalOperator(new StableSortPOperator(physicalOptimizationConfig.getMaxFramesExternalSort()));
    }
    oo.getInputs().add(topOp);
    context.computeAndSetTypeEnvironmentForOperator(oo);
    if (AlgebricksConfig.DEBUG) {
        AlgebricksConfig.ALGEBRICKS_LOGGER.fine(">>>> Added sort enforcer " + oo.getPhysicalOperator() + ".\n");
    }
    return new MutableObject<ILogicalOperator>(oo);
}
Also used : IOrder(org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator.IOrder) OrderColumn(org.apache.hyracks.algebricks.core.algebra.properties.OrderColumn) OrderOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator) InMemoryStableSortPOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.InMemoryStableSortPOperator) LinkedList(java.util.LinkedList) 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) LocalOrderProperty(org.apache.hyracks.algebricks.core.algebra.properties.LocalOrderProperty) InMemoryStableSortPOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.InMemoryStableSortPOperator) AbstractStableSortPOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.AbstractStableSortPOperator) StableSortPOperator(org.apache.hyracks.algebricks.core.algebra.operators.physical.StableSortPOperator) Pair(org.apache.hyracks.algebricks.common.utils.Pair) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Example 12 with LocalOrderProperty

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

the class EnforceStructuralPropertiesRule method getOrderColumnsFromGroupingProperties.

private List<OrderColumn> getOrderColumnsFromGroupingProperties(List<ILocalStructuralProperty> reqd, List<ILocalStructuralProperty> dlvd) {
    List<OrderColumn> returnedProperties = new ArrayList<>();
    List<LogicalVariable> rqdCols = new ArrayList<>();
    List<LogicalVariable> dlvdCols = new ArrayList<>();
    for (ILocalStructuralProperty r : reqd) {
        r.getVariables(rqdCols);
    }
    for (ILocalStructuralProperty d : dlvd) {
        d.getVariables(dlvdCols);
    }
    int prefix = dlvdCols.size() - 1;
    while (prefix >= 0) {
        if (!rqdCols.contains(dlvdCols.get(prefix))) {
            prefix--;
        } else {
            break;
        }
    }
    LocalOrderProperty orderProp = (LocalOrderProperty) dlvd.get(0);
    List<OrderColumn> orderColumns = orderProp.getOrderColumns();
    for (int j = 0; j <= prefix; j++) {
        returnedProperties.add(new OrderColumn(orderColumns.get(j).getColumn(), orderColumns.get(j).getOrder()));
    }
    // maintain other order columns after the required order columns
    if (!returnedProperties.isEmpty()) {
        for (int j = prefix + 1; j < dlvdCols.size(); j++) {
            OrderColumn oc = orderColumns.get(j);
            returnedProperties.add(new OrderColumn(oc.getColumn(), oc.getOrder()));
        }
    }
    return returnedProperties;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) OrderColumn(org.apache.hyracks.algebricks.core.algebra.properties.OrderColumn) LocalOrderProperty(org.apache.hyracks.algebricks.core.algebra.properties.LocalOrderProperty) ArrayList(java.util.ArrayList) ILocalStructuralProperty(org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty)

Example 13 with LocalOrderProperty

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

the class BTreeSearchPOperator method getRequiredPropertiesForChildren.

@Override
public PhysicalRequirements getRequiredPropertiesForChildren(ILogicalOperator op, IPhysicalPropertiesVector reqdByParent, IOptimizationContext context) {
    if (requiresBroadcast) {
        // For primary indexes optimizing an equality condition we can reduce the broadcast requirement to hash partitioning.
        if (isPrimaryIndex && isEqCondition) {
            // If this is a composite primary index, then all of the keys should be provided.
            Index searchIndex = ((DataSourceIndex) idx).getIndex();
            int numberOfKeyFields = searchIndex.getKeyFieldNames().size();
            if (numberOfKeyFields < 2 || (lowKeyVarList.size() == numberOfKeyFields && highKeyVarList.size() == numberOfKeyFields)) {
                StructuralPropertiesVector[] pv = new StructuralPropertiesVector[1];
                ListSet<LogicalVariable> searchKeyVars = new ListSet<>();
                searchKeyVars.addAll(lowKeyVarList);
                searchKeyVars.addAll(highKeyVarList);
                // Also, add a local sorting property to enforce a sort before the primary-index operator.
                List<ILocalStructuralProperty> propsLocal = new ArrayList<>();
                List<OrderColumn> orderColumns = new ArrayList<>();
                for (LogicalVariable orderVar : searchKeyVars) {
                    orderColumns.add(new OrderColumn(orderVar, OrderKind.ASC));
                }
                propsLocal.add(new LocalOrderProperty(orderColumns));
                pv[0] = new StructuralPropertiesVector(new UnorderedPartitionedProperty(searchKeyVars, domain), propsLocal);
                return new PhysicalRequirements(pv, IPartitioningRequirementsCoordinator.NO_COORDINATION);
            }
        }
        StructuralPropertiesVector[] pv = new StructuralPropertiesVector[1];
        pv[0] = new StructuralPropertiesVector(new BroadcastPartitioningProperty(domain), null);
        return new PhysicalRequirements(pv, IPartitioningRequirementsCoordinator.NO_COORDINATION);
    } else {
        return super.getRequiredPropertiesForChildren(op, reqdByParent, context);
    }
}
Also used : StructuralPropertiesVector(org.apache.hyracks.algebricks.core.algebra.properties.StructuralPropertiesVector) LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) UnorderedPartitionedProperty(org.apache.hyracks.algebricks.core.algebra.properties.UnorderedPartitionedProperty) BroadcastPartitioningProperty(org.apache.hyracks.algebricks.core.algebra.properties.BroadcastPartitioningProperty) OrderColumn(org.apache.hyracks.algebricks.core.algebra.properties.OrderColumn) DataSourceIndex(org.apache.asterix.metadata.declared.DataSourceIndex) IDataSourceIndex(org.apache.hyracks.algebricks.core.algebra.metadata.IDataSourceIndex) ArrayList(java.util.ArrayList) DataSourceIndex(org.apache.asterix.metadata.declared.DataSourceIndex) Index(org.apache.asterix.metadata.entities.Index) IDataSourceIndex(org.apache.hyracks.algebricks.core.algebra.metadata.IDataSourceIndex) AlgebricksPartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint) PhysicalRequirements(org.apache.hyracks.algebricks.core.algebra.properties.PhysicalRequirements) ListSet(org.apache.hyracks.algebricks.common.utils.ListSet) LocalOrderProperty(org.apache.hyracks.algebricks.core.algebra.properties.LocalOrderProperty) ILocalStructuralProperty(org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty)

Example 14 with LocalOrderProperty

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

the class AbstractPreclusteredGroupByPOperator method getPropagatedProperty.

// Returns the local structure property that is propagated from an input local structure property
// through a pre-clustered GROUP BY physical operator.
private ILocalStructuralProperty getPropagatedProperty(ILocalStructuralProperty lsp, GroupByOperator gby) {
    PropertyType propertyType = lsp.getPropertyType();
    if (propertyType == PropertyType.LOCAL_GROUPING_PROPERTY) {
        // A new grouping property is generated.
        return new LocalGroupingProperty(new ListSet<>(gby.getGbyVarList()));
    } else {
        LocalOrderProperty lop = (LocalOrderProperty) lsp;
        List<OrderColumn> orderColumns = new ArrayList<>();
        for (OrderColumn oc : lop.getOrderColumns()) {
            LogicalVariable v2 = getLhsGbyVar(gby, oc.getColumn());
            if (v2 != null) {
                orderColumns.add(new OrderColumn(v2, oc.getOrder()));
            } else {
                break;
            }
        }
        // maintained.
        return orderColumns.isEmpty() ? null : new LocalOrderProperty(orderColumns);
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) LocalGroupingProperty(org.apache.hyracks.algebricks.core.algebra.properties.LocalGroupingProperty) LocalOrderProperty(org.apache.hyracks.algebricks.core.algebra.properties.LocalOrderProperty) OrderColumn(org.apache.hyracks.algebricks.core.algebra.properties.OrderColumn) ArrayList(java.util.ArrayList) PropertyType(org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty.PropertyType)

Example 15 with LocalOrderProperty

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

the class AbstractStableSortPOperator method computeLocalProperties.

public void computeLocalProperties(ILogicalOperator op) {
    OrderOperator ord = (OrderOperator) op;
    List<OrderColumn> orderColumns = new ArrayList<OrderColumn>();
    for (Pair<IOrder, Mutable<ILogicalExpression>> p : ord.getOrderExpressions()) {
        ILogicalExpression expr = p.second.getValue();
        if (expr.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
            VariableReferenceExpression varRef = (VariableReferenceExpression) expr;
            LogicalVariable var = varRef.getVariableReference();
            orderColumns.add(new OrderColumn(var, p.first.getKind()));
        } else {
            throw new IllegalStateException();
        }
    }
    sortColumns = orderColumns.toArray(new OrderColumn[orderColumns.size()]);
    orderProp = new LocalOrderProperty(orderColumns);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) IOrder(org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator.IOrder) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) OrderColumn(org.apache.hyracks.algebricks.core.algebra.properties.OrderColumn) LocalOrderProperty(org.apache.hyracks.algebricks.core.algebra.properties.LocalOrderProperty) ArrayList(java.util.ArrayList) OrderOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator)

Aggregations

LocalOrderProperty (org.apache.hyracks.algebricks.core.algebra.properties.LocalOrderProperty)19 ArrayList (java.util.ArrayList)18 OrderColumn (org.apache.hyracks.algebricks.core.algebra.properties.OrderColumn)17 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)15 ILocalStructuralProperty (org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty)15 StructuralPropertiesVector (org.apache.hyracks.algebricks.core.algebra.properties.StructuralPropertiesVector)12 PhysicalRequirements (org.apache.hyracks.algebricks.core.algebra.properties.PhysicalRequirements)8 LinkedList (java.util.LinkedList)5 ListSet (org.apache.hyracks.algebricks.common.utils.ListSet)5 IPartitioningProperty (org.apache.hyracks.algebricks.core.algebra.properties.IPartitioningProperty)5 Mutable (org.apache.commons.lang3.mutable.Mutable)4 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)4 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)4 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)4 IPhysicalPropertiesVector (org.apache.hyracks.algebricks.core.algebra.properties.IPhysicalPropertiesVector)4 LocalGroupingProperty (org.apache.hyracks.algebricks.core.algebra.properties.LocalGroupingProperty)4 UnorderedPartitionedProperty (org.apache.hyracks.algebricks.core.algebra.properties.UnorderedPartitionedProperty)4 HashMap (java.util.HashMap)3 MutableObject (org.apache.commons.lang3.mutable.MutableObject)3 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)3