merged r1323:1324 from hyracks_asterix_stabilizaton -- all caught up

git-svn-id: https://hyracks.googlecode.com/svn/branches/hyracks_lsm_tree@1343 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks-algebricks/hyracks-algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/properties/IPartitioningRequirementsCoordinator.java b/hyracks-algebricks/hyracks-algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/properties/IPartitioningRequirementsCoordinator.java
index 1fff6bb..1230196 100644
--- a/hyracks-algebricks/hyracks-algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/properties/IPartitioningRequirementsCoordinator.java
+++ b/hyracks-algebricks/hyracks-algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/algebra/properties/IPartitioningRequirementsCoordinator.java
@@ -60,10 +60,13 @@
                         Set<LogicalVariable> modifuppreq = new ListSet<LogicalVariable>();
                         Map<LogicalVariable, EquivalenceClass> eqmap = context.getEquivalenceClassMap(op);
                         Set<LogicalVariable> covered = new ListSet<LogicalVariable>();
-                        for (LogicalVariable r : uppreq.getColumnSet()) {
-                            EquivalenceClass ec = eqmap.get(r);
-                            for (LogicalVariable v : set1) {
-                                EquivalenceClass ecFirst = eqmap.get(v);
+
+                        // coordinate from an existing partition property
+                        // (firstDeliveredPartitioning)
+                        for (LogicalVariable v : set1) {
+                            EquivalenceClass ecFirst = eqmap.get(v);
+                            for (LogicalVariable r : uppreq.getColumnSet()) {
+                                EquivalenceClass ec = eqmap.get(r);
                                 if (ecFirst == ec) {
                                     covered.add(v);
                                     modifuppreq.add(r);
@@ -71,6 +74,7 @@
                                 }
                             }
                         }
+
                         if (!covered.equals(set1)) {
                             throw new AlgebricksException("Could not modify " + rqdpp
                                     + " to agree with partitioning property " + firstDeliveredPartitioning
diff --git a/hyracks-algebricks/hyracks-algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/utils/ListSet.java b/hyracks-algebricks/hyracks-algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/utils/ListSet.java
index dbb43ec..44f948f 100644
--- a/hyracks-algebricks/hyracks-algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/utils/ListSet.java
+++ b/hyracks-algebricks/hyracks-algebricks-core/src/main/java/edu/uci/ics/hyracks/algebricks/core/utils/ListSet.java
@@ -7,100 +7,105 @@
 import java.util.Set;
 
 public class ListSet<E> implements Set<E> {
-	private List<E> list = new ArrayList<E>();
+    private List<E> list = new ArrayList<E>();
 
-	public ListSet() {
-	}
+    public ListSet() {
+    }
 
-	public ListSet(Collection<? extends E> arg) {
-		this.addAll(arg);
-	}
+    public ListSet(Collection<? extends E> arg) {
+        this.addAll(arg);
+    }
 
-	@Override
-	public boolean add(E arg0) {
-		return list.add(arg0);
-	}
+    @Override
+    public boolean add(E arg0) {
+        if (list.contains(arg0))
+            return false;
+        return list.add(arg0);
+    }
 
-	@Override
-	public boolean addAll(Collection<? extends E> arg0) {
-		return list.addAll(arg0);
-	}
+    @Override
+    public boolean addAll(Collection<? extends E> arg0) {
+        for (E item : arg0)
+            if (list.contains(item))
+                return false;
+        return list.addAll(arg0);
+    }
 
-	@Override
-	public void clear() {
-		list.clear();
-	}
+    @Override
+    public void clear() {
+        list.clear();
+    }
 
-	@Override
-	public boolean contains(Object arg0) {
-		return list.contains(arg0);
-	}
+    @Override
+    public boolean contains(Object arg0) {
+        return list.contains(arg0);
+    }
 
-	@Override
-	public boolean containsAll(Collection<?> arg0) {
-		return list.containsAll(arg0);
-	}
+    @Override
+    public boolean containsAll(Collection<?> arg0) {
+        return list.containsAll(arg0);
+    }
 
-	@Override
-	public boolean isEmpty() {
-		return list.isEmpty();
-	}
+    @Override
+    public boolean isEmpty() {
+        return list.isEmpty();
+    }
 
-	@Override
-	public Iterator<E> iterator() {
-		return list.iterator();
-	}
+    @Override
+    public Iterator<E> iterator() {
+        return list.iterator();
+    }
 
-	@Override
-	public boolean remove(Object arg0) {
-		return list.remove(arg0);
-	}
+    @Override
+    public boolean remove(Object arg0) {
+        return list.remove(arg0);
+    }
 
-	@Override
-	public boolean removeAll(Collection<?> arg0) {
-		return list.removeAll(arg0);
-	}
+    @Override
+    public boolean removeAll(Collection<?> arg0) {
+        return list.removeAll(arg0);
+    }
 
-	@Override
-	public boolean retainAll(Collection<?> arg0) {
-		return list.retainAll(arg0);
-	}
+    @Override
+    public boolean retainAll(Collection<?> arg0) {
+        return list.retainAll(arg0);
+    }
 
-	@Override
-	public int size() {
-		return list.size();
-	}
+    @Override
+    public int size() {
+        return list.size();
+    }
 
-	@Override
-	public Object[] toArray() {
-		return list.toArray();
-	}
+    @Override
+    public Object[] toArray() {
+        return list.toArray();
+    }
 
-	@Override
-	public <T> T[] toArray(T[] arg0) {
-		return list.toArray(arg0);
-	}
+    @Override
+    public <T> T[] toArray(T[] arg0) {
+        return list.toArray(arg0);
+    }
 
-	@SuppressWarnings("unchecked")
-	@Override
-	public boolean equals(Object arg) {
-		if (!(arg instanceof ListSet))
-			return false;
-		ListSet<E> set = (ListSet<E>) arg;
-		for (E item : set) {
-			if (!this.contains(item))
-				return false;
-		}
-		for (E item : this) {
-			if (!set.contains(item))
-				return false;
-		}
-		return true;
-	}
-	
-	@Override
-	public String toString(){
-		return list.toString();
-	}
+    @SuppressWarnings("unchecked")
+    @Override
+    public boolean equals(Object arg) {
+        if (!(arg instanceof Set))
+            return false;
+        Set<E> set = (Set<E>) arg;
+        for (E item : set) {
+            if (!this.contains(item))
+                return false;
+        }
+        for (E item : this) {
+            if (!set.contains(item))
+                return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return list.toString();
+    }
 
 }