Search in sources :

Example 6 with FunctionalDependency

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

the class EnforceStructuralPropertiesRule method newPropertiesDiff.

private IPhysicalPropertiesVector newPropertiesDiff(AbstractLogicalOperator newChild, IPhysicalPropertiesVector required, boolean mayExpandPartitioningProperties, IOptimizationContext context) throws AlgebricksException {
    IPhysicalPropertiesVector newDelivered = newChild.getDeliveredPhysicalProperties();
    Map<LogicalVariable, EquivalenceClass> newChildEqClasses = context.getEquivalenceClassMap(newChild);
    List<FunctionalDependency> newChildFDs = context.getFDList(newChild);
    if (newChildEqClasses == null || newChildFDs == null) {
        FDsAndEquivClassesVisitor fdsVisitor = new FDsAndEquivClassesVisitor();
        newChild.accept(fdsVisitor, context);
        newChildEqClasses = context.getEquivalenceClassMap(newChild);
        newChildFDs = context.getFDList(newChild);
    }
    AlgebricksConfig.ALGEBRICKS_LOGGER.finest(">>>> Required properties for new op. " + newChild.getPhysicalOperator() + ": " + required + "\n");
    return newDelivered.getUnsatisfiedPropertiesFrom(required, mayExpandPartitioningProperties, newChildEqClasses, newChildFDs);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) FunctionalDependency(org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency) FDsAndEquivClassesVisitor(org.apache.hyracks.algebricks.core.algebra.operators.logical.visitors.FDsAndEquivClassesVisitor) IPhysicalPropertiesVector(org.apache.hyracks.algebricks.core.algebra.properties.IPhysicalPropertiesVector) EquivalenceClass(org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass)

Example 7 with FunctionalDependency

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

the class AbstractFunctionCallExpression method addFD.

private static final void addFD(Collection<FunctionalDependency> fds, LogicalVariable var1, LogicalVariable var2) {
    LinkedList<LogicalVariable> set1 = new LinkedList<LogicalVariable>();
    set1.add(var1);
    LinkedList<LogicalVariable> set2 = new LinkedList<LogicalVariable>();
    set2.add(var2);
    FunctionalDependency fd1 = new FunctionalDependency(set1, set2);
    fds.add(fd1);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) FunctionalDependency(org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency) LinkedList(java.util.LinkedList)

Example 8 with FunctionalDependency

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

the class FDsAndEquivClassesVisitor method visitDataScanOperator.

@Override
public Void visitDataScanOperator(DataSourceScanOperator op, IOptimizationContext ctx) throws AlgebricksException {
    ILogicalOperator inp1 = op.getInputs().get(0).getValue();
    Map<LogicalVariable, EquivalenceClass> eqClasses = getOrCreateEqClasses(op, ctx);
    Map<LogicalVariable, EquivalenceClass> propagatedEqClasses = getOrComputeEqClasses(inp1, ctx);
    eqClasses.putAll(propagatedEqClasses);
    ctx.putEquivalenceClassMap(op, eqClasses);
    List<FunctionalDependency> fds = new ArrayList<FunctionalDependency>(getOrComputeFDs(inp1, ctx));
    ctx.putFDList(op, fds);
    op.getDataSource().computeFDs(op.getVariables(), fds);
    return null;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) FunctionalDependency(org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency) ArrayList(java.util.ArrayList) EquivalenceClass(org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass)

Example 9 with FunctionalDependency

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

the class FDsAndEquivClassesVisitor method visitLeftOuterUnnestMapOperator.

@Override
public Void visitLeftOuterUnnestMapOperator(LeftOuterUnnestMapOperator op, IOptimizationContext ctx) throws AlgebricksException {
    // Unlike the unnest-map operator, we propagate all inputs since
    // propagateInuput is always true.
    Map<LogicalVariable, EquivalenceClass> equivalenceClasses = new HashMap<LogicalVariable, EquivalenceClass>();
    List<FunctionalDependency> functionalDependencies = new ArrayList<FunctionalDependency>();
    ctx.putEquivalenceClassMap(op, equivalenceClasses);
    ctx.putFDList(op, functionalDependencies);
    ILogicalOperator childOp = op.getInputs().get(0).getValue();
    functionalDependencies.addAll(getOrComputeFDs(childOp, ctx));
    equivalenceClasses.putAll(getOrComputeEqClasses(childOp, ctx));
    // Like Left-Outer join case, we add functional dependencies.
    List<LogicalVariable> leftSideVars = new ArrayList<LogicalVariable>();
    List<LogicalVariable> producedVars = new ArrayList<LogicalVariable>();
    VariableUtilities.getUsedVariables(op, leftSideVars);
    VariableUtilities.getProducedVariables(op, leftSideVars);
    functionalDependencies.add(new FunctionalDependency(leftSideVars, producedVars));
    return null;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) HashMap(java.util.HashMap) FunctionalDependency(org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList) EquivalenceClass(org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass)

Example 10 with FunctionalDependency

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

the class FDsAndEquivClassesVisitor method visitLeftOuterJoinOperator.

@Override
public Void visitLeftOuterJoinOperator(LeftOuterJoinOperator op, IOptimizationContext ctx) throws AlgebricksException {
    Map<LogicalVariable, EquivalenceClass> equivalenceClasses = new HashMap<LogicalVariable, EquivalenceClass>();
    List<FunctionalDependency> functionalDependencies = new ArrayList<FunctionalDependency>();
    ctx.putEquivalenceClassMap(op, equivalenceClasses);
    ctx.putFDList(op, functionalDependencies);
    ILogicalOperator opLeft = op.getInputs().get(0).getValue();
    ILogicalOperator opRight = op.getInputs().get(1).getValue();
    functionalDependencies.addAll(getOrComputeFDs(opLeft, ctx));
    functionalDependencies.addAll(getOrComputeFDs(opRight, ctx));
    equivalenceClasses.putAll(getOrComputeEqClasses(opLeft, ctx));
    equivalenceClasses.putAll(getOrComputeEqClasses(opRight, ctx));
    Collection<LogicalVariable> leftSideVars;
    if (opLeft.getSchema() == null) {
        leftSideVars = new LinkedList<LogicalVariable>();
        VariableUtilities.getLiveVariables(opLeft, leftSideVars);
    // actually, not all produced vars. are visible (due to projection)
    // so using cached schema is better and faster
    } else {
        leftSideVars = opLeft.getSchema();
    }
    ILogicalExpression expr = op.getCondition().getValue();
    expr.getConstraintsForOuterJoin(functionalDependencies, leftSideVars);
    return null;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) HashMap(java.util.HashMap) FunctionalDependency(org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList) EquivalenceClass(org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass)

Aggregations

FunctionalDependency (org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency)29 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)27 ArrayList (java.util.ArrayList)22 EquivalenceClass (org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass)16 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)15 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)10 HashSet (java.util.HashSet)8 HashMap (java.util.HashMap)7 LinkedList (java.util.LinkedList)6 Mutable (org.apache.commons.lang3.mutable.Mutable)4 ILocalStructuralProperty (org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty)4 ListSet (org.apache.hyracks.algebricks.common.utils.ListSet)3 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)3 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)3 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)3 LocalGroupingProperty (org.apache.hyracks.algebricks.core.algebra.properties.LocalGroupingProperty)3 Map (java.util.Map)2 Pair (org.apache.hyracks.algebricks.common.utils.Pair)2 GroupByOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator)2 StructuralPropertiesVector (org.apache.hyracks.algebricks.core.algebra.properties.StructuralPropertiesVector)2