mihaibudiu commented on code in PR #4958:
URL: https://github.com/apache/calcite/pull/4958#discussion_r3282868772
##########
core/src/test/java/org/apache/calcite/sql2rel/RelDecorrelatorTest.java:
##########
@@ -1831,6 +1831,85 @@ public static Frameworks.ConfigBuilder config() {
assertThat(after, hasTree(planAfter));
}
+ /** Test case for <a
href="https://issues.apache.org/jira/browse/CALCITE-7540">[CALCITE-7540]
+ * Correlated outer reference in HAVING of grouped subquery is incorrectly
reported as not
+ * grouped</a>. */
+ @Test void test7540() {
+ final FrameworkConfig frameworkConfig = config().build();
+ final RelBuilder builder = RelBuilder.create(frameworkConfig);
+ final RelOptCluster cluster = builder.getCluster();
+ final Planner planner = Frameworks.getPlanner(frameworkConfig);
+ final String sql = ""
+ + "SELECT *\n"
+ + "FROM dept d\n"
+ + "INNER JOIN emp e\n"
+ + " ON e.sal < (\n"
+ + " SELECT MAX(e2.sal)\n"
+ + " FROM emp e2\n"
+ + " WHERE e2.job = e.job\n"
+ + " GROUP BY e2.job\n"
+ + " HAVING MIN(e2.deptno) = d.deptno\n"
+ + " )";
+ final RelNode originalRel;
+ try {
+ final SqlNode parse = planner.parse(sql);
+ final SqlNode validate = planner.validate(parse);
+ originalRel = planner.rel(validate).rel;
+ } catch (Exception e) {
+ throw TestUtil.rethrow(e);
+ }
+
+ final HepProgram hepProgram = HepProgram.builder()
Review Comment:
It looks to me that this test is checking more than just the bug reported in
the issue.
I guess this is necessary because you didn't have any similar tests for such
queries.
##########
core/src/test/resources/sql/sub-query.iq:
##########
@@ -9237,4 +9237,30 @@ SELECT deptno, dname > SOME(SELECT empno FROM emp) AS b
FROM dept;
For input string: "ACCOUNTING"
!error
+# [CALCITE-7540] Correlated outer reference in HAVING of grouped subquery is
incorrectly reported as not grouped
Review Comment:
If this result is validated with another DB please mention it in a comment;
I have seen incorrect tests before, and it's useful for (current and future)
reviewers to know which ones are more trustworthy
--
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]