vlsi commented on a change in pull request #2363:
URL: https://github.com/apache/calcite/pull/2363#discussion_r591220447
##########
File path: core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
##########
@@ -3412,4 +3414,41 @@ public String colType(RelNode rel, int column) {
assertThat(columnOrigin.getOriginTable().getRowType().getFieldNames().get(5),
equalTo("SAL"));
}
+
+ // ----------------------------------------------------------------------
+ // Tests for SortCpuCost
+ // ----------------------------------------------------------------------
+
+ @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);
+ assertThat("query should be sort", rel instanceof LogicalSort);
+ final RelMetadataQuery mq = rel.getCluster().getMetadataQuery();
+ RelOptPlanner planner = new VolcanoPlanner();
+ RelOptCost cost = rel.computeSelfCost(planner, mq);
+ assertThat(cost, notNullValue());
+ final double result = cost.getCpu();
+ assertThat(result, is(expected));
Review comment:
Suppose I have never seen the test code, and I see the following failure
in the CI output:
```
Expected: not null
but: was null
java.lang.AssertionError:
Expected: not null
but: was null
```
What should I do? Why "expected not null"? Why "was null"? What exactly was
null?
The proper assertion failure should look like a good bug report rather than
"go figure out what went wrong".
Bad assertions and bad test code make maintenance much harder.
----------------------------------------------------------------
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]