NobiGo commented on code in PR #3396:
URL: https://github.com/apache/calcite/pull/3396#discussion_r1315268349


##########
core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java:
##########
@@ -1254,6 +1254,54 @@ private void 
checkSemiOrAntiJoinProjectTranspose(JoinRelType type) {
     diffRepos.assertEquals("planAfter", "${planAfter}", planAfter);
   }
 
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-5940";>[CALCITE-5940]
+   * Add the Rules to optimize Limit</a>. */
+  @Test void testLimitMerge() {
+    final String sql = "select deptno from "
+        + "(select deptno from emp where sal > 100 limit 10000) limit 10";
+    sql(sql)
+        .withPreRule(CoreRules.SORT_PROJECT_TRANSPOSE)
+        .withRule(CoreRules.LIMIT_MREGE, CoreRules.PROJECT_REMOVE)
+        .check();
+  }
+
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-5940";>[CALCITE-5940]
+   * Add the Rules to optimize Limit</a>. */
+  @Test void testLimitMerge1() {
+    final String sql = "select deptno from "
+        + "(select deptno from emp where sal > 100 order by sal desc limit 
10000) limit 10";
+    sql(sql)
+        .withPreRule(CoreRules.SORT_PROJECT_TRANSPOSE)
+        .withRule(CoreRules.LIMIT_MREGE, CoreRules.PROJECT_MERGE)
+        .check();
+  }
+
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-5940";>[CALCITE-5940]
+   * Add the Rules to optimize Limit</a>. */
+  @Test void testLimitMerge2() {
+    final String sql = "select deptno from "
+        + "(select deptno from emp where sal > 100 order by sal desc limit 10) 
limit 10000";

Review Comment:
   How about adding tests like:
   `select deptno from (select deptno from emp where sal > 100 order by sal 
desc limit 10) order by deptno limit 10000`
   and 
   
   `select deptno from (select deptno from emp where sal > 100 order by sal 
desc limit 10000) order by deptno limit 10`



-- 
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