[CALCITE-3956] Unify comparison logic for RelOptCost#1944
[CALCITE-3956] Unify comparison logic for RelOptCost#1944liyafan82 wants to merge 4 commits intoapache:masterfrom
Conversation
laurentgo
left a comment
There was a problem hiding this comment.
Let's continue discussion on JIRA before moving on
Agreed. Thank you. |
@zinking Thanks for your good suggestion. I have reverted the changes to the interface. |
I'm sorry, I think I changed my mind after seeing the second implementation file. so your original default implementation is indeed better, because less code and high coupling. |
Thanks again for your reply. Github is having an issue recently, so I thought your comment was swallowed. I have restored the original implementation, and provided a default implementation for the method, so it does not break client code. |
|
After more thoughts and discussions, we have changed the design in another way:
Benefits of this implementation:
Could you please given your valuable feedback? Thank you in advance. |
|
LGTM, but any issue with changing the interface with default logic ? |
Thanks a lot for you feedback. We want to prevent the client from overriding the default comparison logic (isLt, isLe, and equals). We cannot do this with an interface. With an abstract class, however, this can be easily achieved by declaring the method as final. |
|
Since we have not reached an agreement in the discussion, I am closing the issue. |
Currently, comparisons between RelOptCost objects are based on 3 methods:
boolean isLe(RelOptCost cost)boolean isLt(RelOptCost cost)boolean equals(RelOptCost cost)The 3 methods used in combination determine the relation between RelOptCost objects.
There are some problems with this implementation:
if a >=b, then we have a > b or a == bHowever, with the current implementation of VolcanoCost, we can easily create instances that violate the above assertion.
To solve the problems, we want to make RelOptCost extends the Comparable, so the comparison logic is unified in the compareTo method, which solves the above problems.