1 | /* | |
2 | * Copyright OpenSearch Contributors | |
3 | * SPDX-License-Identifier: Apache-2.0 | |
4 | */ | |
5 | ||
6 | ||
7 | package org.opensearch.sql.expression.aggregation; | |
8 | ||
9 | import static org.opensearch.sql.data.model.ExprValueUtils.LITERAL_NULL; | |
10 | import static org.opensearch.sql.utils.ExpressionUtils.format; | |
11 | ||
12 | import java.util.List; | |
13 | import org.opensearch.sql.data.model.ExprValue; | |
14 | import org.opensearch.sql.data.type.ExprCoreType; | |
15 | import org.opensearch.sql.expression.Expression; | |
16 | import org.opensearch.sql.expression.function.BuiltinFunctionName; | |
17 | ||
18 | public class MaxAggregator extends Aggregator<MaxAggregator.MaxState> { | |
19 | ||
20 | public MaxAggregator(List<Expression> arguments, ExprCoreType returnType) { | |
21 | super(BuiltinFunctionName.MAX.getName(), arguments, returnType); | |
22 | } | |
23 | ||
24 | @Override | |
25 | public MaxState create() { | |
26 |
1
1. create : replaced return value with null for org/opensearch/sql/expression/aggregation/MaxAggregator::create → KILLED |
return new MaxState(); |
27 | } | |
28 | ||
29 | @Override | |
30 | protected MaxState iterate(ExprValue value, MaxState state) { | |
31 |
1
1. iterate : removed call to org/opensearch/sql/expression/aggregation/MaxAggregator$MaxState::max → KILLED |
state.max(value); |
32 |
1
1. iterate : replaced return value with null for org/opensearch/sql/expression/aggregation/MaxAggregator::iterate → SURVIVED |
return state; |
33 | } | |
34 | ||
35 | @Override | |
36 | public String toString() { | |
37 |
1
1. toString : replaced return value with "" for org/opensearch/sql/expression/aggregation/MaxAggregator::toString → KILLED |
return String.format("max(%s)", format(getArguments())); |
38 | } | |
39 | ||
40 | protected static class MaxState implements AggregationState { | |
41 | private ExprValue maxResult; | |
42 | ||
43 | MaxState() { | |
44 | maxResult = LITERAL_NULL; | |
45 | } | |
46 | ||
47 | public void max(ExprValue value) { | |
48 |
1
1. max : negated conditional → KILLED |
maxResult = maxResult.isNull() ? value |
49 |
2
1. max : changed conditional boundary → SURVIVED 2. max : negated conditional → KILLED |
: (maxResult.compareTo(value) > 0) |
50 | ? maxResult : value; | |
51 | } | |
52 | ||
53 | @Override | |
54 | public ExprValue result() { | |
55 |
1
1. result : replaced return value with null for org/opensearch/sql/expression/aggregation/MaxAggregator$MaxState::result → KILLED |
return maxResult; |
56 | } | |
57 | } | |
58 | } | |
Mutations | ||
26 |
1.1 |
|
31 |
1.1 |
|
32 |
1.1 |
|
37 |
1.1 |
|
48 |
1.1 |
|
49 |
1.1 2.2 |
|
55 |
1.1 |