[NO ISSUE][COMP] Add equivalence support in DISTINCT FD visitor.

- user model changes: no
- storage format changes: no
- interface changes: no

Detail:
- FD visitor for DISTINCT operator now correctly accounts for
equivalent variables.

Change-Id: I78d66c65864aeacd1713ee60e7f4d221af0eacd1
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/8206
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/FDsAndEquivClassesVisitor.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/FDsAndEquivClassesVisitor.java
index eaac45d..ccdbd1f 100644
--- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/FDsAndEquivClassesVisitor.java
+++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/FDsAndEquivClassesVisitor.java
@@ -189,7 +189,10 @@
             if (p2.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
                 VariableReferenceExpression var2 = (VariableReferenceExpression) p2;
                 LogicalVariable v2 = var2.getVariableReference();
-                if (normSet.contains(v2)) {
+                // We must additionally account for equivalent variables.
+                EquivalenceClass v2EquivalenceClass = equivalenceClasses.get(v2);
+                if ((v2EquivalenceClass != null && normSet.contains(v2EquivalenceClass.getVariableRepresentative()))
+                        || (v2EquivalenceClass == null && normSet.contains(v2))) {
                     newDistinctByList.add(p2Ref);
                 }
             } else {