Skip to content

Commit 28722d5

Browse files
authored
Fix equals and hashcode for SingleValueQuery.LuceneQuery (#110035) (#110048)
Fixes the implementation of equals and hashcode so the lucene queries can be cached.
1 parent 98bfeab commit 28722d5

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

docs/changelog/110035.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 110035
2+
summary: Fix equals and hashcode for `SingleValueQuery.LuceneQuery`
3+
area: ES|QL
4+
type: bug
5+
issues: []

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/querydsl/query/SingleValueQuery.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ Stats stats() {
239239
private static class LuceneQuery extends org.apache.lucene.search.Query {
240240
final org.apache.lucene.search.Query next;
241241
private final IndexFieldData<?> fieldData;
242+
// mutable object for collecting stats and warnings, not really part of the query
242243
private final Stats stats;
243244
private final Warnings warnings;
244245

@@ -283,14 +284,12 @@ public boolean equals(Object obj) {
283284
return false;
284285
}
285286
SingleValueQuery.LuceneQuery other = (SingleValueQuery.LuceneQuery) obj;
286-
return next.equals(other.next)
287-
&& fieldData.getFieldName().equals(other.fieldData.getFieldName())
288-
&& warnings.equals(other.warnings);
287+
return next.equals(other.next) && fieldData.getFieldName().equals(other.fieldData.getFieldName());
289288
}
290289

291290
@Override
292291
public int hashCode() {
293-
return Objects.hash(classHash(), next, fieldData, warnings);
292+
return Objects.hash(classHash(), next, fieldData.getFieldName());
294293
}
295294

296295
@Override

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/querydsl/query/SingleValueQueryTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,16 @@ private void testCase(
230230
if (rewritesToMatchNone != YesNoSometimes.SOMETIMES) {
231231
assertThat(builder.stats().noNextScorer(), equalTo(0));
232232
}
233+
assertEqualsAndHashcodeStable(query, rewritten.toQuery(ctx));
233234
}
234235
}
235236
}
236237

238+
private void assertEqualsAndHashcodeStable(Query query1, Query query2) {
239+
assertEquals(query1, query2);
240+
assertEquals(query1.hashCode(), query2.hashCode());
241+
}
242+
237243
private record StandardSetup(String fieldType, boolean multivaluedField, boolean empty, int count) implements Setup {
238244
@Override
239245
public XContentBuilder mapping(XContentBuilder builder) throws IOException {

0 commit comments

Comments
 (0)