xiedeyantu commented on code in PR #4366:
URL: https://github.com/apache/calcite/pull/4366#discussion_r2082793064
##########
core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java:
##########
@@ -10515,6 +10515,115 @@ private void
checkLoptOptimizeJoinRule(LoptOptimizeJoinRule rule) {
.check();
}
+ /** Test case of
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-6973">[CALCITE-6973]
+ * Add rule for convert Minus to Filter</a>. */
+ @Test void testMinusToFilterRule3() {
+ final String sql = "SELECT mgr, comm FROM emp WHERE comm = 5\n"
+ + "EXCEPT\n"
+ + "SELECT e1.mgr, e1.comm\n"
+ + "FROM emp e1\n"
+ + "WHERE EXISTS (\n"
+ + " SELECT 1 FROM emp e2\n"
+ + " WHERE e2.comm = e1.comm)";
+ sql(sql)
+ .withPreRule(CoreRules.PROJECT_FILTER_TRANSPOSE)
+ .withRule(CoreRules.MINUS_TO_FILTER)
+ .check();
+ }
+
+ /** Test case of
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7002">[CALCITE-7002]
+ * Create an optimization rule to eliminate UNION
+ * from the same source with different filters</a>. */
+ @Test void testUnionToFilterRule() {
+ final String sql = "SELECT mgr, comm FROM emp WHERE mgr = 12\n"
+ + "UNION\n"
+ + "SELECT mgr, comm FROM emp WHERE comm = 5\n";
+ sql(sql)
+ .withPreRule(CoreRules.PROJECT_FILTER_TRANSPOSE)
+ .withRule(CoreRules.UNION_TO_FILTER)
+ .check();
+ }
+
+ /** Test case of
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7002">[CALCITE-7002]
+ * Create an optimization rule to eliminate UNION
+ * from the same source with different filters</a>. */
+ @Test void testUnionToFilterRule2() {
+ final String sql = "SELECT mgr, comm FROM emp\n"
+ + "UNION\n"
+ + "SELECT mgr, comm FROM emp WHERE comm = 5\n";
+ sql(sql)
+ .withPreRule(CoreRules.PROJECT_FILTER_TRANSPOSE)
+ .withRule(CoreRules.UNION_TO_FILTER)
+ .check();
+ }
+
+ /** Test case of
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7002">[CALCITE-7002]
+ * Create an optimization rule to eliminate UNION
+ * from the same source with different filters</a>. */
+ @Test void testUnionToFilterRule3() {
+ final String sql = "SELECT mgr, comm FROM emp WHERE comm = 5\n"
+ + "UNION\n"
+ + "SELECT e1.mgr, e1.comm\n"
+ + "FROM emp e1\n"
+ + "WHERE EXISTS (\n"
+ + " SELECT 1 FROM emp e2\n"
+ + " WHERE e2.comm = e1.comm)";
+ sql(sql)
+ .withPreRule(CoreRules.PROJECT_FILTER_TRANSPOSE)
+ .withRule(CoreRules.UNION_TO_FILTER)
+ .check();
+ }
+
+ /** Test case of
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7002">[CALCITE-7002]
+ * Create an optimization rule to eliminate UNION
+ * from the same source with different filters</a>. */
+ @Test void testIntersectToFilterRule() {
+ final String sql = "SELECT mgr, comm FROM emp WHERE mgr = 12\n"
+ + "INTERSECT\n"
+ + "SELECT mgr, comm FROM emp WHERE comm = 5\n";
+ sql(sql)
+ .withPreRule(CoreRules.PROJECT_FILTER_TRANSPOSE)
+ .withRule(CoreRules.INTERSECT_TO_FILTER)
+ .check();
+ }
+
+ /** Test case of
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7002">[CALCITE-7002]
+ * Create an optimization rule to eliminate UNION
+ * from the same source with different filters</a>. */
+ @Test void testIntersectToFilterRule2() {
+ final String sql = "SELECT mgr, comm FROM emp\n"
+ + "INTERSECT\n"
+ + "SELECT mgr, comm FROM emp WHERE comm = 5\n";
+ sql(sql)
+ .withPreRule(CoreRules.PROJECT_FILTER_TRANSPOSE)
+ .withRule(CoreRules.INTERSECT_TO_FILTER)
+ .check();
+ }
+
+ /** Test case of
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7002">[CALCITE-7002]
+ * Create an optimization rule to eliminate UNION
+ * from the same source with different filters</a>. */
+ @Test void testIntersectToFilterRule3() {
+ final String sql = "SELECT mgr, comm FROM emp WHERE comm = 5\n"
+ + "INTERSECT\n"
+ + "SELECT e1.mgr, e1.comm\n"
+ + "FROM emp e1\n"
+ + "WHERE EXISTS (\n"
Review Comment:
I remember you mentioned in jira that it should be applicable to correlated
subqueries, so I added a case. If it is not needed, I can delete it (maybe it
is really not necessary to add it here).
--
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]