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);
}
}
}
}
Aggregations