Skip to content

Commit c876ad5

Browse files
authored
Fix bucket selector aggregation writeable name. (#773)
* Fixed writeable name. Added constructor for stream input. Signed-off-by: AWSHurneyt <[email protected]> * Moved unit tests from alerting into this package. Signed-off-by: AWSHurneyt <[email protected]> --------- Signed-off-by: AWSHurneyt <[email protected]>
1 parent 6f82a29 commit c876ad5

File tree

2 files changed

+418
-7
lines changed

2 files changed

+418
-7
lines changed

src/main/kotlin/org/opensearch/commons/alerting/aggregation/bucketselectorext/BucketSelectorIndices.kt

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
11
package org.opensearch.commons.alerting.aggregation.bucketselectorext
22

3+
import org.opensearch.core.common.io.stream.StreamInput
34
import org.opensearch.core.common.io.stream.StreamOutput
45
import org.opensearch.core.xcontent.ToXContent
56
import org.opensearch.core.xcontent.XContentBuilder
67
import org.opensearch.search.aggregations.InternalAggregation
78
import java.io.IOException
89
import java.util.Objects
910

10-
open class BucketSelectorIndices(
11-
name: String?,
12-
private var parentBucketPath: String,
13-
var bucketIndices: List<Int?>,
14-
metaData: Map<String?, Any?>?
15-
) : InternalAggregation(name, metaData) {
11+
open class BucketSelectorIndices : InternalAggregation {
12+
private var parentBucketPath: String
13+
var bucketIndices: List<Int?>
14+
15+
constructor(
16+
name: String?,
17+
parentBucketPath: String,
18+
bucketIndices: List<Int?>,
19+
metaData: Map<String?, Any?>?
20+
) : super(name, metaData) {
21+
this.parentBucketPath = parentBucketPath
22+
this.bucketIndices = bucketIndices
23+
}
24+
25+
/**
26+
* Read from a stream.
27+
*/
28+
@Throws(IOException::class)
29+
constructor(sin: StreamInput) : super(sin) {
30+
parentBucketPath = sin.readString()
31+
bucketIndices = sin.readIntArray().asList()
32+
}
1633

1734
@Throws(IOException::class)
1835
override fun doWriteTo(out: StreamOutput) {
@@ -21,7 +38,7 @@ open class BucketSelectorIndices(
2138
}
2239

2340
override fun getWriteableName(): String {
24-
return name
41+
return BucketSelectorExtAggregationBuilder.NAME.preferredName
2542
}
2643

2744
override fun reduce(aggregations: List<InternalAggregation>, reduceContext: ReduceContext): BucketSelectorIndices {

0 commit comments

Comments
 (0)