Search in sources :

Example 6 with ListSet

use of org.apache.hyracks.algebricks.common.utils.ListSet in project asterixdb by apache.

the class LocalGroupingProperty method retainVariables.

@Override
public ILocalStructuralProperty retainVariables(Collection<LogicalVariable> vars) {
    Set<LogicalVariable> newVars = new ListSet<>();
    newVars.addAll(vars);
    newVars.retainAll(columnSet);
    if (columnSet.equals(newVars)) {
        return new LocalGroupingProperty(columnSet, preferredOrderEnforcer);
    }
    // Column set for the retained grouping property
    Set<LogicalVariable> newColumns = new ListSet<>();
    // Matches the prefix of the original column set.
    for (LogicalVariable v : columnSet) {
        if (newVars.contains(v)) {
            newColumns.add(v);
        } else {
            break;
        }
    }
    return createNewLocalGroupingProperty(newColumns);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ListSet(org.apache.hyracks.algebricks.common.utils.ListSet)

Example 7 with ListSet

use of org.apache.hyracks.algebricks.common.utils.ListSet in project asterixdb by apache.

the class PropertiesUtil method closureUnderFDs.

public Set<LogicalVariable> closureUnderFDs(Collection<LogicalVariable> vars, List<FunctionalDependency> fdList) {
    Set<LogicalVariable> k = new ListSet<>(vars);
    boolean change;
    do {
        change = false;
        for (FunctionalDependency fd : fdList) {
            List<LogicalVariable> h = fd.getHead();
            if (!k.containsAll(h)) {
                continue;
            }
            List<LogicalVariable> t = fd.getTail();
            for (LogicalVariable v : t) {
                if (!(k.contains(v))) {
                    k.add(v);
                    change = true;
                }
            }
        }
    } while (change);
    return k;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ListSet(org.apache.hyracks.algebricks.common.utils.ListSet)

Example 8 with ListSet

use of org.apache.hyracks.algebricks.common.utils.ListSet in project asterixdb by apache.

the class EliminateSubplanWithInputCardinalityOneRule method rewritePre.

@Override
public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    if (!invoked) {
        rootRef = opRef;
        invoked = true;
    }
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    if (op.getInputs().size() <= 0) {
        return false;
    }
    boolean changed = false;
    for (Mutable<ILogicalOperator> subplanRef : op.getInputs()) {
        AbstractLogicalOperator op1 = (AbstractLogicalOperator) subplanRef.getValue();
        if (op1.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
            continue;
        }
        SubplanOperator subplan = (SubplanOperator) op1;
        Set<LogicalVariable> usedVarsUp = new ListSet<LogicalVariable>();
        OperatorPropertiesUtil.getFreeVariablesInPath(rootRef.getValue(), subplan, usedVarsUp);
        // TODO(buyingyi): figure out the rewriting for subplan operators with multiple subplans.
        if (subplan.getNestedPlans().size() != 1) {
            continue;
        }
        ILogicalOperator subplanInputOperator = subplan.getInputs().get(0).getValue();
        Set<LogicalVariable> subplanInputVars = new ListSet<LogicalVariable>();
        VariableUtilities.getLiveVariables(subplanInputOperator, subplanInputVars);
        int subplanInputVarSize = subplanInputVars.size();
        subplanInputVars.removeAll(usedVarsUp);
        // Makes sure the free variables are only used in the subplan.
        if (subplanInputVars.size() < subplanInputVarSize) {
            continue;
        }
        Set<LogicalVariable> freeVars = new ListSet<LogicalVariable>();
        OperatorPropertiesUtil.getFreeVariablesInSubplans(subplan, freeVars);
        boolean cardinalityOne = isCardinalityOne(subplan.getInputs().get(0), freeVars);
        if (cardinalityOne) {
            /** If the cardinality of freeVars in the subplan is one, the subplan can be removed. */
            ILogicalPlan plan = subplan.getNestedPlans().get(0);
            List<Mutable<ILogicalOperator>> rootRefs = plan.getRoots();
            // TODO(buyingyi): investigate the case of multi-root plans.
            if (rootRefs.size() != 1) {
                continue;
            }
            // Replaces all Nts' in the nested plan with the Subplan input operator or its deep copy.
            ILogicalOperator topOperator = rootRefs.get(0).getValue();
            ReplaceNtsWithSubplanInputOperatorVisitor visitor = new ReplaceNtsWithSubplanInputOperatorVisitor(context, subplan);
            ILogicalOperator newTopOperator = topOperator.accept(visitor, null);
            subplanRef.setValue(newTopOperator);
            OperatorManipulationUtil.computeTypeEnvironmentBottomUp(newTopOperator, context);
            changed = true;
        } else {
            continue;
        }
    }
    return changed;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) SubplanOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.SubplanOperator) Mutable(org.apache.commons.lang3.mutable.Mutable) ListSet(org.apache.hyracks.algebricks.common.utils.ListSet) ILogicalPlan(org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)

Example 9 with ListSet

use of org.apache.hyracks.algebricks.common.utils.ListSet in project asterixdb by apache.

the class DataSourcePartitioningProvider method getFeedPartitioningProperty.

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

Example 10 with ListSet

use of org.apache.hyracks.algebricks.common.utils.ListSet in project asterixdb by apache.

the class JoinMultiComparator method deliveredLocalProperties.

@Override
protected List<ILocalStructuralProperty> deliveredLocalProperties(ILogicalOperator op, IOptimizationContext context) throws AlgebricksException {
    List<ILocalStructuralProperty> deliveredLocalProperties = new ArrayList<>();
    // Inner join can kick off the "role reversal" optimization, which can kill data properties for the probe side.
    if (kind != JoinKind.LEFT_OUTER) {
        return deliveredLocalProperties;
    }
    AbstractLogicalOperator probeOp = (AbstractLogicalOperator) op.getInputs().get(0).getValue();
    IPhysicalPropertiesVector probeSideProperties = probeOp.getPhysicalOperator().getDeliveredProperties();
    List<ILocalStructuralProperty> probeSideLocalProperties = probeSideProperties.getLocalProperties();
    if (probeSideLocalProperties != null) {
        // is destroyed.
        for (ILocalStructuralProperty property : probeSideLocalProperties) {
            Set<LogicalVariable> groupingVars = new ListSet<>();
            Set<LogicalVariable> leftBranchVars = new ListSet<>();
            property.getVariables(groupingVars);
            leftBranchVars.addAll(getKeysLeftBranch());
            if (groupingVars.containsAll(leftBranchVars)) {
                deliveredLocalProperties.add(new LocalGroupingProperty(groupingVars));
            }
        }
    }
    return deliveredLocalProperties;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ListSet(org.apache.hyracks.algebricks.common.utils.ListSet) LocalGroupingProperty(org.apache.hyracks.algebricks.core.algebra.properties.LocalGroupingProperty) ArrayList(java.util.ArrayList) IPhysicalPropertiesVector(org.apache.hyracks.algebricks.core.algebra.properties.IPhysicalPropertiesVector) ILocalStructuralProperty(org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty)

Aggregations

ListSet (org.apache.hyracks.algebricks.common.utils.ListSet)22 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)22 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)13 ArrayList (java.util.ArrayList)12 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)10 Mutable (org.apache.commons.lang3.mutable.Mutable)9 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)9 ILocalStructuralProperty (org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty)9 StructuralPropertiesVector (org.apache.hyracks.algebricks.core.algebra.properties.StructuralPropertiesVector)7 HashSet (java.util.HashSet)6 GroupByOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator)6 LocalGroupingProperty (org.apache.hyracks.algebricks.core.algebra.properties.LocalGroupingProperty)6 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)5 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)5 IPartitioningProperty (org.apache.hyracks.algebricks.core.algebra.properties.IPartitioningProperty)5 LocalOrderProperty (org.apache.hyracks.algebricks.core.algebra.properties.LocalOrderProperty)5 UnorderedPartitionedProperty (org.apache.hyracks.algebricks.core.algebra.properties.UnorderedPartitionedProperty)5 LinkedList (java.util.LinkedList)4 IPhysicalPropertiesVector (org.apache.hyracks.algebricks.core.algebra.properties.IPhysicalPropertiesVector)4 OrderColumn (org.apache.hyracks.algebricks.core.algebra.properties.OrderColumn)4