1 | /* | |
2 | * Copyright OpenSearch Contributors | |
3 | * SPDX-License-Identifier: Apache-2.0 | |
4 | */ | |
5 | ||
6 | package org.opensearch.sql.planner.physical.collector; | |
7 | ||
8 | import java.util.AbstractMap; | |
9 | import java.util.Collections; | |
10 | import java.util.LinkedHashMap; | |
11 | import java.util.List; | |
12 | import java.util.Map; | |
13 | import java.util.stream.Collectors; | |
14 | import org.opensearch.sql.data.model.ExprTupleValue; | |
15 | import org.opensearch.sql.data.model.ExprValue; | |
16 | import org.opensearch.sql.expression.aggregation.AggregationState; | |
17 | import org.opensearch.sql.expression.aggregation.NamedAggregator; | |
18 | import org.opensearch.sql.storage.bindingtuple.BindingTuple; | |
19 | ||
20 | /** | |
21 | * Each {@link NamedAggregator} defined in aggregators collect metrics from {@link BindingTuple}. | |
22 | */ | |
23 | public class MetricCollector implements Collector { | |
24 | ||
25 | /** | |
26 | * List of {@link NamedAggregator}. | |
27 | */ | |
28 | private final List<Map.Entry<NamedAggregator, AggregationState>> aggregators; | |
29 | ||
30 | /** | |
31 | * Constructor of {@link MetricCollector}. | |
32 | * | |
33 | * @param aggregators aggregators. | |
34 | */ | |
35 | public MetricCollector(List<NamedAggregator> aggregators) { | |
36 | this.aggregators = | |
37 | aggregators.stream() | |
38 |
1
1. lambda$new$0 : replaced return value with null for org/opensearch/sql/planner/physical/collector/MetricCollector::lambda$new$0 → KILLED |
.map(aggregator -> new AbstractMap.SimpleEntry<>(aggregator, aggregator.create())) |
39 | .collect(Collectors.toList()); | |
40 | } | |
41 | ||
42 | /** | |
43 | * Collect Metrics from BindingTuple. | |
44 | * | |
45 | * @param input {@link BindingTuple}. | |
46 | */ | |
47 | public void collect(BindingTuple input) { | |
48 |
1
1. collect : removed call to java/util/List::forEach → KILLED |
aggregators.forEach( |
49 | agg -> { | |
50 | agg.getKey().iterate(input, agg.getValue()); | |
51 | }); | |
52 | } | |
53 | ||
54 | /** | |
55 | * Get aggregation result from aggregators. | |
56 | * | |
57 | * @return List of {@link ExprValue}. | |
58 | */ | |
59 | public List<ExprValue> results() { | |
60 | LinkedHashMap<String, ExprValue> map = new LinkedHashMap<>(); | |
61 |
1
1. results : removed call to java/util/List::forEach → KILLED |
aggregators.forEach(agg -> map.put(agg.getKey().getName(), agg.getValue().result())); |
62 |
1
1. results : replaced return value with Collections.emptyList for org/opensearch/sql/planner/physical/collector/MetricCollector::results → KILLED |
return Collections.singletonList(ExprTupleValue.fromExprValueMap(map)); |
63 | } | |
64 | } | |
Mutations | ||
38 |
1.1 |
|
48 |
1.1 |
|
61 |
1.1 |
|
62 |
1.1 |