Skip to content

Commit

Permalink
Fix bucket selector aggregation writeable name. (#773)
Browse files Browse the repository at this point in the history
* Fixed writeable name. Added constructor for stream input.

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>

* Moved unit tests from alerting into this package.

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>

---------

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
  • Loading branch information
AWSHurneyt authored Jan 28, 2025
1 parent 6f82a29 commit c876ad5
Show file tree
Hide file tree
Showing 2 changed files with 418 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
package org.opensearch.commons.alerting.aggregation.bucketselectorext

import org.opensearch.core.common.io.stream.StreamInput
import org.opensearch.core.common.io.stream.StreamOutput
import org.opensearch.core.xcontent.ToXContent
import org.opensearch.core.xcontent.XContentBuilder
import org.opensearch.search.aggregations.InternalAggregation
import java.io.IOException
import java.util.Objects

open class BucketSelectorIndices(
name: String?,
private var parentBucketPath: String,
var bucketIndices: List<Int?>,
metaData: Map<String?, Any?>?
) : InternalAggregation(name, metaData) {
open class BucketSelectorIndices : InternalAggregation {
private var parentBucketPath: String
var bucketIndices: List<Int?>

constructor(
name: String?,
parentBucketPath: String,
bucketIndices: List<Int?>,
metaData: Map<String?, Any?>?
) : super(name, metaData) {
this.parentBucketPath = parentBucketPath
this.bucketIndices = bucketIndices
}

/**
* Read from a stream.
*/
@Throws(IOException::class)
constructor(sin: StreamInput) : super(sin) {
parentBucketPath = sin.readString()
bucketIndices = sin.readIntArray().asList()
}

@Throws(IOException::class)
override fun doWriteTo(out: StreamOutput) {
Expand All @@ -21,7 +38,7 @@ open class BucketSelectorIndices(
}

override fun getWriteableName(): String {
return name
return BucketSelectorExtAggregationBuilder.NAME.preferredName
}

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

0 comments on commit c876ad5

Please sign in to comment.