|
51 | 51 | import org.opensearch.search.aggregations.InternalAggregation; |
52 | 52 | import org.opensearch.search.aggregations.LeafBucketCollector; |
53 | 53 | import org.opensearch.search.aggregations.LeafBucketCollectorBase; |
| 54 | +import org.opensearch.search.aggregations.ShardResultConvertor; |
54 | 55 | import org.opensearch.search.aggregations.StarTreeBucketCollector; |
55 | 56 | import org.opensearch.search.aggregations.StarTreePreComputeCollector; |
56 | 57 | import org.opensearch.search.aggregations.support.ValuesSource; |
|
59 | 60 | import org.opensearch.search.startree.StarTreeQueryHelper; |
60 | 61 |
|
61 | 62 | import java.io.IOException; |
| 63 | +import java.util.ArrayList; |
| 64 | +import java.util.List; |
62 | 65 | import java.util.Map; |
63 | 66 |
|
64 | 67 | import static org.opensearch.search.startree.StarTreeQueryHelper.getStarTreeFilteredValues; |
|
69 | 72 | * |
70 | 73 | * @opensearch.internal |
71 | 74 | */ |
72 | | -class AvgAggregator extends NumericMetricsAggregator.SingleValue implements StarTreePreComputeCollector { |
| 75 | +class AvgAggregator extends NumericMetricsAggregator.SingleValue implements StarTreePreComputeCollector, ShardResultConvertor { |
73 | 76 |
|
74 | 77 | final ValuesSource.Numeric valuesSource; |
75 | 78 |
|
@@ -275,4 +278,15 @@ public void collectStarTreeEntry(int starTreeEntryBit, long bucket) throws IOExc |
275 | 278 | } |
276 | 279 | }; |
277 | 280 | } |
| 281 | + |
| 282 | + @Override |
| 283 | + public List<InternalAggregation> convert(Map<String, Object[]> shardResult) { |
| 284 | + Object[] counts = shardResult.get(name + "_count"); |
| 285 | + Object[] sums = shardResult.get(name + "_sum"); |
| 286 | + List<InternalAggregation> results = new ArrayList<>(counts.length); |
| 287 | + for (int i = 0; i < counts.length; i++) { |
| 288 | + results.add(new InternalAvg(name, (Long) counts[i], (Long) sums[i], format, metadata())); |
| 289 | + } |
| 290 | + return results; |
| 291 | + } |
278 | 292 | } |
0 commit comments