Search in sources :

Example 11 with ILocalStructuralProperty

use of org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty 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)

Example 12 with ILocalStructuralProperty

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

the class IntersectPOperator method getRequiredPropertiesForChildren.

@Override
public PhysicalRequirements getRequiredPropertiesForChildren(ILogicalOperator iop, IPhysicalPropertiesVector reqdByParent, IOptimizationContext context) {
    IntersectOperator intersectOp = (IntersectOperator) iop;
    StructuralPropertiesVector[] pv = new StructuralPropertiesVector[intersectOp.getNumInput()];
    for (int i = 0; i < intersectOp.getNumInput(); i++) {
        List<ILocalStructuralProperty> localProps = new ArrayList<>();
        List<OrderColumn> orderColumns = new ArrayList<>();
        for (LogicalVariable column : intersectOp.getInputVariables(i)) {
            orderColumns.add(new OrderColumn(column, OrderOperator.IOrder.OrderKind.ASC));
        }
        localProps.add(new LocalOrderProperty(orderColumns));
        IPartitioningProperty pp = null;
        if (intersectOp.getExecutionMode() == AbstractLogicalOperator.ExecutionMode.PARTITIONED) {
            Set<LogicalVariable> partitioningVariables = new HashSet<>(intersectOp.getInputVariables(i));
            pp = new UnorderedPartitionedProperty(partitioningVariables, null);
        }
        pv[i] = new StructuralPropertiesVector(pp, localProps);
    }
    return new PhysicalRequirements(pv, IPartitioningRequirementsCoordinator.NO_COORDINATION);
}
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) OrderColumn(org.apache.hyracks.algebricks.core.algebra.properties.OrderColumn) ArrayList(java.util.ArrayList) IPartitioningProperty(org.apache.hyracks.algebricks.core.algebra.properties.IPartitioningProperty) PhysicalRequirements(org.apache.hyracks.algebricks.core.algebra.properties.PhysicalRequirements) LocalOrderProperty(org.apache.hyracks.algebricks.core.algebra.properties.LocalOrderProperty) IntersectOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.IntersectOperator) ILocalStructuralProperty(org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty) HashSet(java.util.HashSet)

Example 13 with ILocalStructuralProperty

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

the class HashPartitionMergeExchangePOperator method computeDeliveredProperties.

@Override
public void computeDeliveredProperties(ILogicalOperator op, IOptimizationContext context) {
    IPartitioningProperty p = new UnorderedPartitionedProperty(new ListSet<LogicalVariable>(partitionFields), domain);
    AbstractLogicalOperator op2 = (AbstractLogicalOperator) op.getInputs().get(0).getValue();
    List<ILocalStructuralProperty> op2Locals = op2.getDeliveredPhysicalProperties().getLocalProperties();
    List<ILocalStructuralProperty> locals = new ArrayList<ILocalStructuralProperty>();
    for (ILocalStructuralProperty prop : op2Locals) {
        if (prop.getPropertyType() == PropertyType.LOCAL_ORDER_PROPERTY) {
            locals.add(prop);
        } else {
            break;
        }
    }
    this.deliveredProperties = new StructuralPropertiesVector(p, locals);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) StructuralPropertiesVector(org.apache.hyracks.algebricks.core.algebra.properties.StructuralPropertiesVector) UnorderedPartitionedProperty(org.apache.hyracks.algebricks.core.algebra.properties.UnorderedPartitionedProperty) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ArrayList(java.util.ArrayList) ILocalStructuralProperty(org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty) IPartitioningProperty(org.apache.hyracks.algebricks.core.algebra.properties.IPartitioningProperty)

Example 14 with ILocalStructuralProperty

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

the class AbstractPropagatePropertiesForUsedVariablesPOperator method computeDeliveredPropertiesForUsedVariables.

public void computeDeliveredPropertiesForUsedVariables(ILogicalOperator op, List<LogicalVariable> usedVariables) {
    ILogicalOperator op2 = op.getInputs().get(0).getValue();
    IPartitioningProperty pp = op2.getDeliveredPhysicalProperties().getPartitioningProperty();
    List<ILocalStructuralProperty> downPropsLocal = op2.getDeliveredPhysicalProperties().getLocalProperties();
    List<ILocalStructuralProperty> propsLocal = new ArrayList<ILocalStructuralProperty>();
    if (downPropsLocal != null) {
        for (ILocalStructuralProperty lsp : downPropsLocal) {
            LinkedList<LogicalVariable> cols = new LinkedList<LogicalVariable>();
            lsp.getColumns(cols);
            ILocalStructuralProperty propagatedProp = lsp.retainVariables(usedVariables);
            if (propagatedProp != null) {
                propsLocal.add(propagatedProp);
            }
        }
    }
    deliveredProperties = new StructuralPropertiesVector(pp, propsLocal);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) StructuralPropertiesVector(org.apache.hyracks.algebricks.core.algebra.properties.StructuralPropertiesVector) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList) ILocalStructuralProperty(org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty) IPartitioningProperty(org.apache.hyracks.algebricks.core.algebra.properties.IPartitioningProperty) LinkedList(java.util.LinkedList)

Example 15 with ILocalStructuralProperty

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

the class FDsAndEquivClassesVisitor method visitDistinctOperator.

@Override
public Void visitDistinctOperator(DistinctOperator op, IOptimizationContext ctx) throws AlgebricksException {
    ILogicalOperator op0 = op.getInputs().get(0).getValue();
    List<FunctionalDependency> functionalDependencies = new ArrayList<FunctionalDependency>();
    ctx.putFDList(op, functionalDependencies);
    for (FunctionalDependency inherited : getOrComputeFDs(op0, ctx)) {
        boolean isCoveredByDistinctByVars = true;
        for (LogicalVariable v : inherited.getHead()) {
            if (!op.isDistinctByVar(v)) {
                isCoveredByDistinctByVars = false;
            }
        }
        if (isCoveredByDistinctByVars) {
            List<LogicalVariable> newTail = new ArrayList<LogicalVariable>();
            for (LogicalVariable v2 : inherited.getTail()) {
                if (op.isDistinctByVar(v2)) {
                    newTail.add(v2);
                }
            }
            if (!newTail.isEmpty()) {
                List<LogicalVariable> newHead = new ArrayList<LogicalVariable>(inherited.getHead());
                FunctionalDependency newFd = new FunctionalDependency(newHead, newTail);
                functionalDependencies.add(newFd);
            }
        }
    }
    Set<LogicalVariable> gbySet = new HashSet<LogicalVariable>();
    List<Mutable<ILogicalExpression>> expressions = op.getExpressions();
    for (Mutable<ILogicalExpression> pRef : expressions) {
        ILogicalExpression p = pRef.getValue();
        if (p.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
            VariableReferenceExpression v = (VariableReferenceExpression) p;
            gbySet.add(v.getVariableReference());
        }
    }
    LocalGroupingProperty lgp = new LocalGroupingProperty(gbySet);
    Map<LogicalVariable, EquivalenceClass> equivalenceClasses = getOrComputeEqClasses(op0, ctx);
    ctx.putEquivalenceClassMap(op, equivalenceClasses);
    ILocalStructuralProperty normalizedLgp = lgp.normalize(equivalenceClasses, functionalDependencies);
    Set<LogicalVariable> normSet = new ListSet<>();
    normalizedLgp.getColumns(normSet);
    List<Mutable<ILogicalExpression>> newDistinctByList = new ArrayList<Mutable<ILogicalExpression>>();
    for (Mutable<ILogicalExpression> p2Ref : expressions) {
        ILogicalExpression p2 = p2Ref.getValue();
        if (p2.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
            VariableReferenceExpression var2 = (VariableReferenceExpression) p2;
            LogicalVariable v2 = var2.getVariableReference();
            if (normSet.contains(v2)) {
                newDistinctByList.add(p2Ref);
            }
        } else {
            newDistinctByList.add(p2Ref);
        }
    }
    expressions.clear();
    expressions.addAll(newDistinctByList);
    return null;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) LocalGroupingProperty(org.apache.hyracks.algebricks.core.algebra.properties.LocalGroupingProperty) ArrayList(java.util.ArrayList) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) ListSet(org.apache.hyracks.algebricks.common.utils.ListSet) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) FunctionalDependency(org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency) EquivalenceClass(org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass) ILocalStructuralProperty(org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty) HashSet(java.util.HashSet)

Aggregations

ILocalStructuralProperty (org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty)30 ArrayList (java.util.ArrayList)24 StructuralPropertiesVector (org.apache.hyracks.algebricks.core.algebra.properties.StructuralPropertiesVector)22 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)19 LocalOrderProperty (org.apache.hyracks.algebricks.core.algebra.properties.LocalOrderProperty)15 OrderColumn (org.apache.hyracks.algebricks.core.algebra.properties.OrderColumn)14 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)13 IPhysicalPropertiesVector (org.apache.hyracks.algebricks.core.algebra.properties.IPhysicalPropertiesVector)11 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)10 IPartitioningProperty (org.apache.hyracks.algebricks.core.algebra.properties.IPartitioningProperty)10 ListSet (org.apache.hyracks.algebricks.common.utils.ListSet)9 LinkedList (java.util.LinkedList)8 PhysicalRequirements (org.apache.hyracks.algebricks.core.algebra.properties.PhysicalRequirements)8 LocalGroupingProperty (org.apache.hyracks.algebricks.core.algebra.properties.LocalGroupingProperty)7 UnorderedPartitionedProperty (org.apache.hyracks.algebricks.core.algebra.properties.UnorderedPartitionedProperty)6 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)5 GroupByOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 FunctionalDependency (org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency)4