vlsi commented on a change in pull request #2363:
URL: https://github.com/apache/calcite/pull/2363#discussion_r591334749



##########
File path: core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
##########
@@ -3412,4 +3415,41 @@ public String colType(RelNode rel, int column) {
     
assertThat(columnOrigin.getOriginTable().getRowType().getFieldNames().get(5),
         equalTo("SAL"));
   }
+
+  @Test void testSortCpuCostOffsetLimit() {
+    final String sql = "select ename from emp order by ename limit 5 offset 5";
+    double cpuCost = EMP_SIZE * Math.log(10) * 4;
+    checkCpuCost(sql, cpuCost);
+  }
+
+  @Test void testSortCpuCostLimit() {
+    final String sql = "select ename from emp limit 10";
+    checkCpuCost(sql, 0d);
+  }
+
+  @Test void testSortCpuCostLimit0() {
+    final String sql = "select ename from emp order by ename limit 0";
+    checkCpuCost(sql, 0d);
+  }
+
+  @Test void testSortCpuCostLargeLimit() {
+    final String sql = "select ename from emp order by ename limit 10000";
+    double cpuCost = EMP_SIZE * Math.log(EMP_SIZE) * 4;
+    checkCpuCost(sql, cpuCost);
+  }
+
+  private void checkCpuCost(String sql, double expected) {
+    RelNode rel = convertSql(sql);
+    RelOptCost cost = computeRelSelfCost(rel);
+    final double result = cost.getCpu();
+    assertEquals(expected, result, () -> "cpu cost is not as expected <"
+        + expected + ">, but <" + result + ">, plan as follow:\n"
+        + RelOptUtil.toString(rel, SqlExplainLevel.ALL_ATTRIBUTES));

Review comment:
       You've added `...<"        + expected + ">, but <" + result + ">...` to 
the exception message. However, it would make the message complicated with no 
extra gain.
   `assertEquals` would print `expected` vs `actual` on its own, so `message` 
parameter (which you write in the test code) *must not* include `expected vs 
actual`.
   
   On the other hand, `message` parameter must explain **why** the value is 
expected like that.
   
   For instance: "sort limit exceeds table size => cost should be dominated by 
table size", "limit is 0, cost must be 0", and so on.




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


Reply via email to