Skip to content

[CALCITE-2632] Add hashCode and equals implementations to RexNode.#943

Closed
kgyrtkirk wants to merge 2 commits intoapache:masterfrom
kgyrtkirk:2632-rexNode-hashCode-submit
Closed

[CALCITE-2632] Add hashCode and equals implementations to RexNode.#943
kgyrtkirk wants to merge 2 commits intoapache:masterfrom
kgyrtkirk:2632-rexNode-hashCode-submit

Conversation

@kgyrtkirk
Copy link
Member

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.

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])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is digest initialized by the time hashCode is executed?
Should toString be used here?

Copy link
Member Author

@kgyrtkirk kgyrtkirk Nov 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"...

julianhyde added a commit to julianhyde/calcite that referenced this pull request Nov 30, 2018
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
julianhyde added a commit to julianhyde/calcite that referenced this pull request Nov 30, 2018
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
julianhyde pushed a commit to julianhyde/calcite that referenced this pull request Dec 1, 2018
…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
@asfgit asfgit closed this in 847e76c Dec 2, 2018
F21 pushed a commit to F21/calcite that referenced this pull request Jan 3, 2019
…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
wangxlong pushed a commit to wangxlong/calcite that referenced this pull request Feb 13, 2020
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants