mihaibudiu commented on code in PR #5235:
URL: https://github.com/apache/calcite/pull/5235#discussion_r4319318118


##########
core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java:
##########
@@ -405,6 +406,36 @@ public static boolean containsNullable(RelDataType type) {
     return false;
   }
 
+  /**
+   * Returns whether a type or any type nested within its fields, collection
+   * component, map key, or map value matches a predicate.
+   */
+  public static boolean containsType(RelDataType type,

Review Comment:
   containsMatchingType is a better name



##########
core/src/test/java/org/apache/calcite/test/RelMetadataTest.java:
##########
@@ -709,6 +722,62 @@ final RelMetadataFixture sql(String sql) {
     assertThat(mq.determines(relNode, empNo, dname), is(Boolean.FALSE));
   }
 
+  @Test void testFunctionalDependencyOuterJoinEqualityDirection() {

Review Comment:
   Missing JavaDoc on test.



##########
core/src/test/java/org/apache/calcite/test/AggregateRemoveDuplicateKeysRuleTest.java:
##########
@@ -72,6 +72,74 @@ private static RelOptFixture sql(String sql) {
         .check();
   }
 
+  @Test void testKeepsGroupKeyFromPreservedSideOfLeftJoin() {
+    // The null-generating right key cannot determine the preserved left key:
+    // unmatched rows with different e.deptno values all have d.deptno = NULL.
+    final String sql = "select d.deptno, e.deptno, count(*) as c\n"
+        + "from emp e\n"
+        + "left join dept d on e.deptno = d.deptno\n"
+        + "group by d.deptno, e.deptno";
+
+    sql(sql).withRule(CoreRules.AGGREGATE_REMOVE_DUPLICATE_KEYS)
+        .checkUnchanged();
+  }
+
+  @Test void testKeepsFdFromNullGeneratingInputOfLeftJoin() {
+    // This FD comes from the right input rather than from the join condition.
+    // The right Project has a -> COALESCE(a, 1), but null padding adds a row
+    // with a = NULL and y = NULL alongside the matched a = NULL, y = 1 row.
+    final String sql = "select r.a, r.y, count(*) as c\n"
+        + "from (values (1), (2)) as l(z)\n"
+        + "left join (\n"
+        + "  select z, a, coalesce(a, 1) as y\n"
+        + "  from (values (1, cast(null as integer))) as v(z, a)\n"
+        + ") as r on l.z = r.z\n"
+        + "group by r.a, r.y";
+
+    sql(sql).withRule(CoreRules.AGGREGATE_REMOVE_DUPLICATE_KEYS)
+        .checkUnchanged();
+  }
+
+  @Test void testMapsFdForNonContiguousAggregateGroupSet() {
+    // AggregateProjectMergeRule changes the input group set to {1, 2, 3},
+    // whose keys occupy output positions {0, 1, 2}. Map the input FD 1 -> 2

Review Comment:
   Is this comment valid before or after the fix? If it's before the fix, the 
comment is already wrong.



##########
core/src/test/java/org/apache/calcite/test/RelMetadataTest.java:
##########
@@ -374,6 +375,18 @@ final RelMetadataFixture sql(String sql) {
     assertThat(mq.determines(relNode, sumSal, count), is(Boolean.FALSE));
   }
 
+  @Test void testFunctionalDependencyRollupAggregate() {

Review Comment:
   Is this a test case for this issue? Then it needs JavaDoc with a specific 
format. There are lots of examples to follow.



##########
core/src/test/java/org/apache/calcite/test/AggregateRemoveDuplicateKeysRuleTest.java:
##########
@@ -72,6 +72,74 @@ private static RelOptFixture sql(String sql) {
         .check();
   }
 
+  @Test void testKeepsGroupKeyFromPreservedSideOfLeftJoin() {
+    // The null-generating right key cannot determine the preserved left key:
+    // unmatched rows with different e.deptno values all have d.deptno = NULL.
+    final String sql = "select d.deptno, e.deptno, count(*) as c\n"
+        + "from emp e\n"
+        + "left join dept d on e.deptno = d.deptno\n"
+        + "group by d.deptno, e.deptno";
+
+    sql(sql).withRule(CoreRules.AGGREGATE_REMOVE_DUPLICATE_KEYS)
+        .checkUnchanged();
+  }
+
+  @Test void testKeepsFdFromNullGeneratingInputOfLeftJoin() {
+    // This FD comes from the right input rather than from the join condition.

Review Comment:
   Which FD? Maybe you can explain what FDs are inferred.



##########
core/src/test/java/org/apache/calcite/test/AggregateRemoveDuplicateKeysRuleTest.java:
##########
@@ -72,6 +72,74 @@ private static RelOptFixture sql(String sql) {
         .check();
   }
 
+  @Test void testKeepsGroupKeyFromPreservedSideOfLeftJoin() {
+    // The null-generating right key cannot determine the preserved left key:

Review Comment:
   For a reader it's not obvious at all how this test relates to this comment.
   You need longer explanations on these tests.



##########
core/src/test/java/org/apache/calcite/test/AggregateRemoveDuplicateKeysRuleTest.java:
##########
@@ -72,6 +72,74 @@ private static RelOptFixture sql(String sql) {
         .check();
   }
 
+  @Test void testKeepsGroupKeyFromPreservedSideOfLeftJoin() {

Review Comment:
   no JavaDoc on tests.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to