Skip to content

Commit 6a4b18c

Browse files
committed
upd
1 parent 1320be5 commit 6a4b18c

File tree

10 files changed

+63
-104
lines changed

10 files changed

+63
-104
lines changed

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/Attribute.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,15 @@ protected Expression canonicalize() {
112112
}
113113

114114
@Override
115+
@SuppressWarnings("checkstyle:EqualsHashCode")// equals is implemented in parent. See innerEquals instead
115116
public int hashCode() {
116117
return Objects.hash(super.hashCode(), nullability);
117118
}
118119

119120
@Override
120-
public boolean equals(Object obj) {
121-
if (this == obj) {
122-
return true;
123-
}
124-
if (obj == null || getClass() != obj.getClass() || super.equals(obj) == false) {
125-
return false;
126-
}
127-
Attribute other = (Attribute) obj;
128-
return Objects.equals(nullability, other.nullability);
121+
protected boolean innerEquals(Object o) {
122+
var other = (Attribute) o;
123+
return super.innerEquals(other) && Objects.equals(nullability, other.nullability);
129124
}
130125

131126
@Override

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/EmptyAttribute.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,13 @@ protected NodeInfo<? extends Expression> info() {
6060
}
6161

6262
@Override
63+
@SuppressWarnings("checkstyle:EqualsHashCode")// equals is implemented in parent. See innerEquals instead
6364
public int hashCode() {
6465
return EmptyAttribute.class.hashCode();
6566
}
6667

6768
@Override
68-
public boolean equals(Object obj) {
69-
if (this == obj) {
70-
return true;
71-
}
72-
if (obj == null || getClass() != obj.getClass()) {
73-
return false;
74-
}
69+
protected boolean innerEquals(Object o) {
7570
return true;
7671
}
7772
}

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/FieldAttribute.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,20 +223,15 @@ public Attribute withDataType(DataType type) {
223223
}
224224

225225
@Override
226-
public boolean equals(Object o) {
227-
if (this == o) {
228-
return true;
229-
}
230-
if (o == null || getClass() != o.getClass() || super.equals(o) == false) {
231-
return false;
232-
}
233-
FieldAttribute that = (FieldAttribute) o;
234-
return Objects.equals(parentName, that.parentName) && Objects.equals(field, that.field);
226+
@SuppressWarnings("checkstyle:EqualsHashCode")// equals is implemented in parent. See innerEquals instead
227+
public int hashCode() {
228+
return Objects.hash(super.hashCode(), parentName, field);
235229
}
236230

237231
@Override
238-
public int hashCode() {
239-
return Objects.hash(super.hashCode(), parentName, field);
232+
protected boolean innerEquals(Object o) {
233+
var other = (FieldAttribute) o;
234+
return super.innerEquals(other) && Objects.equals(parentName, other.parentName) && Objects.equals(field, other.field);
240235
}
241236

242237
@Override

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/MetadataAttribute.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,14 @@ public static boolean isSupported(String name) {
173173
}
174174

175175
@Override
176-
public boolean equals(Object o) {
177-
if (this == o) {
178-
return true;
179-
}
180-
if (o == null || getClass() != o.getClass() || super.equals(o) == false) {
181-
return false;
182-
}
183-
MetadataAttribute that = (MetadataAttribute) o;
184-
return searchable == that.searchable;
176+
@SuppressWarnings("checkstyle:EqualsHashCode")// equals is implemented in parent. See innerEquals instead
177+
public int hashCode() {
178+
return Objects.hash(super.hashCode(), searchable);
185179
}
186180

187181
@Override
188-
public int hashCode() {
189-
return Objects.hash(super.hashCode(), searchable);
182+
protected boolean innerEquals(Object o) {
183+
var other = (MetadataAttribute) o;
184+
return super.innerEquals(other) && searchable == other.searchable;
190185
}
191186
}

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/NamedExpression.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,25 @@ public int hashCode() {
6161
return Objects.hash(super.hashCode(), name, synthetic);
6262
}
6363

64+
/**
65+
* Polymorphic equality is a pain.
66+
* This equals shortcuts `this == o` and type checks.
67+
* Here equals is final to ensure we are not duplication those checks.
68+
* For actual equality check override `innerEquals` instead.
69+
*/
6470
@Override
65-
public boolean equals(Object obj) {
66-
if (this == obj) {
71+
public final boolean equals(Object o) {
72+
if (this == o) {
6773
return true;
6874
}
69-
if (obj == null || getClass() != obj.getClass()) {
75+
if (o == null || getClass() != o.getClass()) {
7076
return false;
7177
}
72-
NamedExpression other = (NamedExpression) obj;
78+
return innerEquals(o);
79+
}
80+
81+
protected boolean innerEquals(Object o) {
82+
var other = (NamedExpression) o;
7383
return synthetic == other.synthetic
7484
/*
7585
* It is important that the line below be `name`

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/TypedAttribute.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,14 @@ public DataType dataType() {
3434
}
3535

3636
@Override
37-
public boolean equals(Object o) {
38-
if (this == o) {
39-
return true;
40-
}
41-
if (o == null || getClass() != o.getClass() || super.equals(o) == false) {
42-
return false;
43-
}
44-
TypedAttribute that = (TypedAttribute) o;
45-
return dataType == that.dataType;
37+
@SuppressWarnings("checkstyle:EqualsHashCode")// equals is implemented in parent. See innerEquals instead
38+
public int hashCode() {
39+
return Objects.hash(super.hashCode(), dataType);
4640
}
4741

4842
@Override
49-
public int hashCode() {
50-
return Objects.hash(super.hashCode(), dataType);
43+
protected boolean innerEquals(Object o) {
44+
var other = (TypedAttribute) o;
45+
return super.innerEquals(other) && dataType == other.dataType;
5146
}
5247
}

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/UnresolvedAttribute.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,17 @@ public static String errorMessage(String name, List<String> potentialMatches) {
119119
}
120120

121121
@Override
122-
public boolean equals(Object o) {
123-
if (this == o) {
124-
return true;
125-
}
126-
if (o == null || getClass() != o.getClass() || super.equals(o) == false) {
127-
return false;
128-
}
129-
UnresolvedAttribute that = (UnresolvedAttribute) o;
130-
return customMessage == that.customMessage
131-
&& Objects.equals(unresolvedMsg, that.unresolvedMsg)
132-
&& Objects.equals(resolutionMetadata, that.resolutionMetadata);
122+
@SuppressWarnings("checkstyle:EqualsHashCode")// equals is implemented in parent. See innerEquals instead
123+
public int hashCode() {
124+
return Objects.hash(super.hashCode(), resolutionMetadata, unresolvedMsg);
133125
}
134126

135127
@Override
136-
public int hashCode() {
137-
return Objects.hash(super.hashCode(), resolutionMetadata, unresolvedMsg);
128+
protected boolean innerEquals(Object o) {
129+
var other = (UnresolvedAttribute) o;
130+
return super.innerEquals(other)
131+
&& customMessage == other.customMessage
132+
&& Objects.equals(unresolvedMsg, other.unresolvedMsg)
133+
&& Objects.equals(resolutionMetadata, other.resolutionMetadata);
138134
}
139135
}

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/UnresolvedStar.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,15 @@ public UnresolvedAttribute qualifier() {
5757
}
5858

5959
@Override
60+
@SuppressWarnings("checkstyle:EqualsHashCode")// equals is implemented in parent. See innerEquals instead
6061
public int hashCode() {
6162
return Objects.hash(qualifier);
6263
}
6364

6465
@Override
65-
public boolean equals(Object obj) {
66-
/*
67-
* Intentionally not calling the superclass
68-
* equals because it uses id which we always
69-
* mutate when we make a clone. So we need
70-
* to ignore it in equals for the transform
71-
* tests to pass.
72-
*/
73-
if (this == obj) {
74-
return true;
75-
}
76-
if (obj == null || obj.getClass() != getClass()) {
77-
return false;
78-
}
79-
UnresolvedStar other = (UnresolvedStar) obj;
80-
return Objects.equals(qualifier, other.qualifier);
66+
protected boolean innerEquals(Object o) {
67+
var other = (UnresolvedStar) o;
68+
return super.innerEquals(other) && Objects.equals(qualifier, other.qualifier);
8169
}
8270

8371
private String message() {

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/UnresolvedNamePattern.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,15 @@ public Nullability nullable() {
9898
}
9999

100100
@Override
101-
public boolean equals(Object o) {
102-
if (this == o) {
103-
return true;
104-
}
105-
if (o == null || getClass() != o.getClass() || super.equals(o) == false) {
106-
return false;
107-
}
108-
UnresolvedNamePattern that = (UnresolvedNamePattern) o;
109-
return Objects.equals(pattern, that.pattern);
101+
@SuppressWarnings("checkstyle:EqualsHashCode")// equals is implemented in parent. See innerEquals instead
102+
public int hashCode() {
103+
return Objects.hash(super.hashCode(), pattern);
110104
}
111105

112106
@Override
113-
public int hashCode() {
114-
return Objects.hash(super.hashCode(), pattern);
107+
protected boolean innerEquals(Object o) {
108+
var other = (UnresolvedNamePattern) o;
109+
return super.innerEquals(other) && Objects.equals(pattern, other.pattern);
115110
}
116111

117112
@Override

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/UnsupportedAttribute.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,15 @@ public boolean hasCustomMessage() {
163163
}
164164

165165
@Override
166-
public boolean equals(Object o) {
167-
if (this == o) {
168-
return true;
169-
}
170-
if (o == null || getClass() != o.getClass() || super.equals(o) == false) {
171-
return false;
172-
}
173-
UnsupportedAttribute that = (UnsupportedAttribute) o;
174-
return hasCustomMessage == that.hasCustomMessage && Objects.equals(message, that.message);
166+
@SuppressWarnings("checkstyle:EqualsHashCode")// equals is implemented in parent. See innerEquals instead
167+
public int hashCode() {
168+
return Objects.hash(super.hashCode(), message, hasCustomMessage);
175169
}
176170

177171
@Override
178-
public int hashCode() {
179-
return Objects.hash(super.hashCode(), message, hasCustomMessage);
172+
protected boolean innerEquals(Object o) {
173+
var other = (UnsupportedAttribute) o;
174+
return super.innerEquals(other) && hasCustomMessage == other.hasCustomMessage && Objects.equals(message, other.message);
180175
}
181176

182177
@Override

0 commit comments

Comments
 (0)