Skip to content

Commit 466f15a

Browse files
committed
Fix matrix_stats aggregation cache conflict by including multiValueMode in equals/hashCode
- Added multiValueMode to equals() and hashCode() of MatrixStatsAggregationBuilder - Added serialization/deserialization logic for multiValueMode in writeTo/readFrom - Prevents incorrect aggregator reuse when aggregation mode changes (e.g. AVG ↔ MIN)
1 parent 58c281f commit 466f15a

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

modules/aggs-matrix-stats/src/main/java/org/opensearch/search/aggregations/matrix/stats/MatrixStatsAggregationBuilder.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
import java.io.IOException;
4747
import java.util.Map;
48+
import java.util.Objects;
4849

4950
public class MatrixStatsAggregationBuilder extends ArrayValuesSourceAggregationBuilder.LeafOnly<MatrixStatsAggregationBuilder> {
5051
public static final String NAME = "matrix_stats";
@@ -74,22 +75,19 @@ protected AggregationBuilder shallowCopy(AggregatorFactories.Builder factoriesBu
7475
*/
7576
public MatrixStatsAggregationBuilder(StreamInput in) throws IOException {
7677
super(in);
78+
this.multiValueMode = in.readEnum(MultiValueMode.class);
7779
}
7880

7981
@Override
80-
protected void innerWriteTo(StreamOutput out) {
81-
// Do nothing, no extra state to write to stream
82+
protected void innerWriteTo(StreamOutput out) throws IOException {
83+
out.writeEnum(multiValueMode);
8284
}
8385

8486
public MatrixStatsAggregationBuilder multiValueMode(MultiValueMode multiValueMode) {
8587
this.multiValueMode = multiValueMode;
8688
return this;
8789
}
8890

89-
public MultiValueMode multiValueMode() {
90-
return this.multiValueMode;
91-
}
92-
9391
@Override
9492
protected MatrixStatsAggregatorFactory innerBuild(
9593
QueryShardContext queryShardContext,
@@ -110,4 +108,18 @@ public XContentBuilder doXContentBody(XContentBuilder builder, ToXContent.Params
110108
public String getType() {
111109
return NAME;
112110
}
111+
112+
@Override
113+
public boolean equals(Object obj) {
114+
if (this == obj) return true;
115+
if (obj == null || getClass() != obj.getClass()) return false;
116+
if (super.equals(obj) == false) return false;
117+
MatrixStatsAggregationBuilder other = (MatrixStatsAggregationBuilder) obj;
118+
return multiValueMode == other.multiValueMode;
119+
}
120+
121+
@Override
122+
public int hashCode() {
123+
return Objects.hash(super.hashCode(), multiValueMode);
124+
}
113125
}

0 commit comments

Comments
 (0)