Search in sources :

Example 16 with OrderColumn

use of org.apache.hyracks.algebricks.core.algebra.properties.OrderColumn 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 17 with OrderColumn

use of org.apache.hyracks.algebricks.core.algebra.properties.OrderColumn 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 18 with OrderColumn

use of org.apache.hyracks.algebricks.core.algebra.properties.OrderColumn 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 19 with OrderColumn

use of org.apache.hyracks.algebricks.core.algebra.properties.OrderColumn 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 20 with OrderColumn

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

the class SubstituteVariableVisitor method visitAssignOperator.

@Override
public Void visitAssignOperator(AssignOperator op, Pair<LogicalVariable, LogicalVariable> pair) throws AlgebricksException {
    List<LogicalVariable> variables = op.getVariables();
    int n = variables.size();
    for (int i = 0; i < n; i++) {
        if (variables.get(i).equals(pair.first)) {
            variables.set(i, pair.second);
        } else {
            op.getExpressions().get(i).getValue().substituteVar(pair.first, pair.second);
        }
    }
    // Substitute variables stored in ordering property
    if (op.getExplicitOrderingProperty() != null) {
        List<OrderColumn> orderColumns = op.getExplicitOrderingProperty().getOrderColumns();
        for (int i = 0; i < orderColumns.size(); i++) {
            OrderColumn oc = orderColumns.get(i);
            if (oc.getColumn().equals(pair.first)) {
                orderColumns.set(i, new OrderColumn(pair.second, oc.getOrder()));
            }
        }
    }
    substVarTypes(op, pair);
    return null;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) OrderColumn(org.apache.hyracks.algebricks.core.algebra.properties.OrderColumn)

Aggregations

OrderColumn (org.apache.hyracks.algebricks.core.algebra.properties.OrderColumn)26 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)22 ArrayList (java.util.ArrayList)18 LocalOrderProperty (org.apache.hyracks.algebricks.core.algebra.properties.LocalOrderProperty)17 ILocalStructuralProperty (org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty)14 StructuralPropertiesVector (org.apache.hyracks.algebricks.core.algebra.properties.StructuralPropertiesVector)12 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)7 PhysicalRequirements (org.apache.hyracks.algebricks.core.algebra.properties.PhysicalRequirements)7 LinkedList (java.util.LinkedList)6 IPartitioningProperty (org.apache.hyracks.algebricks.core.algebra.properties.IPartitioningProperty)6 IVariableTypeEnvironment (org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment)5 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)5 IBinaryComparatorFactoryProvider (org.apache.hyracks.algebricks.data.IBinaryComparatorFactoryProvider)5 INormalizedKeyComputerFactoryProvider (org.apache.hyracks.algebricks.data.INormalizedKeyComputerFactoryProvider)5 IBinaryComparatorFactory (org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory)5 INormalizedKeyComputerFactory (org.apache.hyracks.api.dataflow.value.INormalizedKeyComputerFactory)5 Mutable (org.apache.commons.lang3.mutable.Mutable)4 ListSet (org.apache.hyracks.algebricks.common.utils.ListSet)4 Pair (org.apache.hyracks.algebricks.common.utils.Pair)4 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)4