jinxing64 commented on a change in pull request #1451: [CALCITE-3334] 
Refinement for Substitution-Based MV Matching
URL: https://github.com/apache/calcite/pull/1451#discussion_r324680479
 
 

 ##########
 File path: core/src/test/java/org/apache/calcite/test/MaterializationTest.java
 ##########
 @@ -588,6 +604,90 @@ private void checkNoMaterialize(String materialize, 
String query,
     checkMaterialize(mv, query);
   }
 
+  /**
+   * Matching failed because the filtering condition under Aggregate
+   * references columns for aggregation.
+   */
+  @Test public void testAggregate4() {
+    String mv = ""
+        + "select * from\n"
+        + "(select \"deptno\", sum(\"salary\") as \"sum_salary\", 
sum(\"commission\")\n"
+        + "from " + deduplicatedEmps + "\n"
+        + "group by \"deptno\")\n"
+        + "where \"sum_salary\" > 10";
+    String query = ""
+        + "select * from\n"
+        + "(select \"deptno\", sum(\"salary\") as \"sum_salary\"\n"
+        + "from " + deduplicatedEmps + "\n"
+        + "where \"salary\" > 1000\n"
+        + "group by \"deptno\")\n"
+        + "where \"sum_salary\" > 10";
+    checkNoMaterialize(mv, query, HR_FKUK_MODEL);
+  }
+
+  /**
+   * There will be a compensating Project added after matching of the 
Aggregate.
+   * This rule targets to test if the Calc can be handled.
+   */
+  @Test public void testCompensatingCalcWithAggregate0() {
+    String mv = ""
+        + "select * from\n"
+        + "(select \"deptno\", sum(\"salary\") as \"sum_salary\", 
sum(\"commission\")\n"
+        + "from " + deduplicatedEmps + "\n"
+        + "group by \"deptno\")\n"
+        + "where \"sum_salary\" > 10";
+    String query = ""
+        + "select * from\n"
+        + "(select \"deptno\", sum(\"salary\") as \"sum_salary\"\n"
+        + "from " + deduplicatedEmps + "\n"
+        + "group by \"deptno\")\n"
+        + "where \"sum_salary\" > 10";
+    checkMaterialize(mv, query);
+  }
+
+  /**
+   * There will be a compensating Project + Filter added after matching of the 
Aggregate.
+   * This rule targets to test if the Calc can be handled.
+   */
+  @Test public void testCompensatingCalcWithAggregate1() {
+    String mv = ""
+        + "select * from\n"
+        + "(select \"deptno\", sum(\"salary\") as \"sum_salary\", 
sum(\"commission\")\n"
+        + "from " + deduplicatedEmps + "\n"
+        + "group by \"deptno\")\n"
+        + "where \"sum_salary\" > 10";
+    String query = ""
+        + "select * from\n"
+        + "(select \"deptno\", sum(\"salary\") as \"sum_salary\"\n"
+        + "from " + deduplicatedEmps + "\n"
+        + "where \"deptno\" >=20\n"
+        + "group by \"deptno\")\n"
+        + "where \"sum_salary\" > 10";
+    checkMaterialize(mv, query);
+  }
+
+  /**
+   * There will be a compensating Project + Filter added after matching of the 
Aggregate.
 
 Review comment:
   Yes, it is.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to