Skip to content

Commit 1ec951a

Browse files
committed
Using Scripted Avg Class in AvgAggregationBuilder in place of double
Signed-off-by: Kshitij Tandon <tandonks@amazon.com>
1 parent eb2d244 commit 1ec951a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/main/kotlin/org/opensearch/indexmanagement/rollup/util/RollupUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,13 @@ fun Rollup.rewriteAggregationBuilder(aggregationBuilder: AggregationBuilder): Ag
240240
.combineScript(
241241
Script(
242242
ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG,
243-
"def d = new double[2]; d[0] = state.sums; d[1] = state.counts; return d", emptyMap(),
243+
"def d = new org.opensearch.search.aggregations.metrics.ScriptedAvg(state.sums, state.counts); return d", emptyMap(),
244244
),
245245
)
246246
.reduceScript(
247247
Script(
248248
ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG,
249-
"double sum = 0; double count = 0; for (a in states) { sum += a[0]; count += a[1]; } return sum/count", emptyMap(),
249+
"double sum = 0; double count = 0; for (a in states) { sum += a.getSum(); count += a.getCount(); } return sum/count", emptyMap(),
250250
),
251251
)
252252
}

src/test/kotlin/org/opensearch/indexmanagement/rollup/interceptor/RollupInterceptorIT.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,8 @@ class RollupInterceptorIT : RollupRestTestCase() {
11031103
},
11041104
"aggs": {
11051105
"sum_passenger_count": { "sum": { "field": "passenger_count" } },
1106-
"max_passenger_count": { "max": { "field": "passenger_count" } }
1106+
"max_passenger_count": { "max": { "field": "passenger_count" } },
1107+
"value_count_passenger_count": { "value_count": { "field": "passenger_count" } }
11071108
}
11081109
}
11091110
""".trimIndent()

0 commit comments

Comments
 (0)