[refactor] (Nereids) add equals for OrderKey (#11192)

LogicalSort.equals() method depends on OrderKey.equals(), which is not defined correctly.
This pr defines OrderKey.equals() to enable correctly comparing LogicalSort.
This commit is contained in:
minghong
2022-07-26 18:55:27 +08:00
committed by GitHub
parent e99f617b21
commit fcdb543e17

View File

@ -19,6 +19,8 @@ package org.apache.doris.nereids.properties;
import org.apache.doris.nereids.trees.expressions.Expression;
import java.util.Objects;
/**
* Represents the order key of a statement.
*/
@ -67,4 +69,21 @@ public class OrderKey {
public String toString() {
return expr.toSql();
}
@Override
public int hashCode() {
return Objects.hash(expr, isAsc, nullFirst);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
OrderKey that = (OrderKey) o;
return isAsc == that.isAsc() && nullFirst == that.isNullFirst() && expr.equals(that.getExpr());
}
}