[CALCITE-2632] Add hashCode and equals implementations to RexNode.#943
[CALCITE-2632] Add hashCode and equals implementations to RexNode.#943kgyrtkirk wants to merge 2 commits intoapache:masterfrom
Conversation
Previously there was no default hashCode/equals implementations. To ensure that they are working properly is cruical while working with basic collections like sets/maps.
| LogicalFilter(condition=[=($1, $0)]) | ||
| LogicalProject(D4=[+($0, 4)], D5=[+($0, 5)], D6=[+($0, 6)]) | ||
| LogicalTableScan(table=[[CATALOG, SALES, DEPT]]) | ||
| LogicalJoin(condition=[true], joinType=[inner]) |
There was a problem hiding this comment.
I think this change is "okay" mostly this plan change is due to that now it makes more use of d4=d.d1 and d5=d.d1 which implies d4=d5
| } | ||
|
|
||
| @Override public int hashCode() { | ||
| return Objects.hash(digest, type, id); |
There was a problem hiding this comment.
is digest initialized by the time hashCode is executed?
Should toString be used here?
There was a problem hiding this comment.
the parent class initializes it - but I understand your concern...I think the general question would be to use digest or not...
| if (!(obj instanceof RexCall)) { | ||
| return false; | ||
| } | ||
| return obj == this || Objects.equals(toString(), obj.toString()); |
There was a problem hiding this comment.
Do you mean toString should be a long-term solution?
Do you mean this would be reworked in future? (e.g. to avoid string build for the sole purpose of equals)
There was a problem hiding this comment.
I'm not sure...but we shouldn't use node.toString() everywhere when we are comparing RexNode-s...that's even worse...
I think the rational behind using digest instead of real tree comparison is to avoid the recursive comparision/etc - as long as when someone creates digest; remembers this design decision I think we are okay - but; for the record: I wouldn't expect this from a field like "digest"...
Use Objects.equals(x, y) in preference to x.equals(y) only when x or y
may be null; and use x == y when objects are primitive.
When implementing Object.equals, use the pattern
return this == obj
|| obj instanceof Type
&& a1.equals(obj.a1) ...
whenever possible.
Close apache#943
Use Objects.equals(x, y) in preference to x.equals(y) only when x or y
may be null; and use x == y when objects are primitive.
When implementing Object.equals, use the pattern
return this == obj
|| obj instanceof Type
&& a1.equals(obj.a1) ...
whenever possible.
In the many cases where RexNode.toString() is used as a key in
collections, use the raw RexNode instead.
Close apache#943
…Code and equals methods (Zoltan Haindrich)
Previously there was no default hashCode/equals implementations. To
ensure that they are working properly is crucial while working with
basic collections like sets/maps.
Fix ups (Julian Hyde):
* Use Objects.equals(x, y) in preference to x.equals(y) only when x or y
may be null; and use x == y when objects are primitive.
* When implementing Object.equals, use the pattern
return this == obj
|| obj instanceof Type
&& a.equals(((Type) obj).a) ...
whenever possible.
* In the many cases where RexNode.toString() is used as a key in
collections, use the raw RexNode instead.
Close apache#943
…Code and equals methods (Zoltan Haindrich)
Previously there was no default hashCode/equals implementations. To
ensure that they are working properly is crucial while working with
basic collections like sets/maps.
Fix ups (Julian Hyde):
* Use Objects.equals(x, y) in preference to x.equals(y) only when x or y
may be null; and use x == y when objects are primitive.
* When implementing Object.equals, use the pattern
return this == obj
|| obj instanceof Type
&& a.equals(((Type) obj).a) ...
whenever possible.
* In the many cases where RexNode.toString() is used as a key in
collections, use the raw RexNode instead.
Close apache#943
…Code and equals methods (Zoltan Haindrich)
Previously there was no default hashCode/equals implementations. To
ensure that they are working properly is crucial while working with
basic collections like sets/maps.
Fix ups (Julian Hyde):
* Use Objects.equals(x, y) in preference to x.equals(y) only when x or y
may be null; and use x == y when objects are primitive.
* When implementing Object.equals, use the pattern
return this == obj
|| obj instanceof Type
&& a.equals(((Type) obj).a) ...
whenever possible.
* In the many cases where RexNode.toString() is used as a key in
collections, use the raw RexNode instead.
Close apache#943
Previously there was no default hashCode/equals implementations.
To ensure that they are working properly is cruical while working with basic collections like sets/maps.