Search in sources :

Example 21 with EquivalenceClass

use of org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass in project asterixdb by apache.

the class AbstractFunctionCallExpression method getFDsAndEquivClassesForColumnEq.

/*
     * Obs.: mgmt. of equiv. classes should use a more efficient data
     * structure,if we are to implem. cost-bazed optim.
     */
private static final void getFDsAndEquivClassesForColumnEq(VariableReferenceExpression v1, VariableReferenceExpression v2, Collection<FunctionalDependency> fds, Map<LogicalVariable, EquivalenceClass> equivClasses) {
    LogicalVariable var1 = v1.getVariableReference();
    LogicalVariable var2 = v2.getVariableReference();
    LinkedList<LogicalVariable> set1 = new LinkedList<LogicalVariable>();
    set1.add(var1);
    LinkedList<LogicalVariable> set2 = new LinkedList<LogicalVariable>();
    set2.add(var2);
    FunctionalDependency fd1 = new FunctionalDependency(set1, set2);
    FunctionalDependency fd2 = new FunctionalDependency(set2, set1);
    fds.add(fd1);
    fds.add(fd2);
    EquivalenceClass ec1 = equivClasses.get(var1);
    EquivalenceClass ec2 = equivClasses.get(var2);
    if (ec1 == null && ec2 == null) {
        LinkedList<LogicalVariable> members = new LinkedList<LogicalVariable>();
        members.add(var1);
        members.add(var2);
        EquivalenceClass ec = new EquivalenceClass(members, var1);
        equivClasses.put(var1, ec);
        equivClasses.put(var2, ec);
    } else if (ec1 == null && ec2 != null) {
        ec2.addMember(var1);
        equivClasses.put(var1, ec2);
    } else if (ec2 == null && ec1 != null) {
        ec1.addMember(var2);
        equivClasses.put(var2, ec1);
    } else {
        ec1.merge(ec2);
        for (LogicalVariable w : equivClasses.keySet()) {
            if (ec2.getMembers().contains(w)) {
                equivClasses.put(w, ec1);
            }
        }
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) FunctionalDependency(org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency) EquivalenceClass(org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass) LinkedList(java.util.LinkedList)

Aggregations

EquivalenceClass (org.apache.hyracks.algebricks.core.algebra.base.EquivalenceClass)21 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)21 FunctionalDependency (org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency)16 ArrayList (java.util.ArrayList)14 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)14 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)11 HashMap (java.util.HashMap)7 LinkedList (java.util.LinkedList)5 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)4 HashSet (java.util.HashSet)3 Mutable (org.apache.commons.lang3.mutable.Mutable)3 ListSet (org.apache.hyracks.algebricks.common.utils.ListSet)3 List (java.util.List)2 AInt32 (org.apache.asterix.om.base.AInt32)2 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)2 Pair (org.apache.hyracks.algebricks.common.utils.Pair)2 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)2 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)2 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)2 ILocalStructuralProperty (org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty)2