MinAggregator.java

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
/**
19
 * The minimum aggregator aggregate the value evaluated by the expression.
20
 * If the expression evaluated result is NULL or MISSING, then the result is NULL.
21
 */
22
public class MinAggregator extends Aggregator<MinAggregator.MinState> {
23
24
  public MinAggregator(List<Expression> arguments, ExprCoreType returnType) {
25
    super(BuiltinFunctionName.MIN.getName(), arguments, returnType);
26
  }
27
28
29
  @Override
30
  public MinState create() {
31 1 1. create : replaced return value with null for org/opensearch/sql/expression/aggregation/MinAggregator::create → KILLED
    return new MinState();
32
  }
33
34
  @Override
35
  protected MinState iterate(ExprValue value, MinState state) {
36 1 1. iterate : removed call to org/opensearch/sql/expression/aggregation/MinAggregator$MinState::min → KILLED
    state.min(value);
37 1 1. iterate : replaced return value with null for org/opensearch/sql/expression/aggregation/MinAggregator::iterate → SURVIVED
    return state;
38
  }
39
40
  @Override
41
  public String toString() {
42 1 1. toString : replaced return value with "" for org/opensearch/sql/expression/aggregation/MinAggregator::toString → KILLED
    return String.format("min(%s)", format(getArguments()));
43
  }
44
45
  protected static class MinState implements AggregationState {
46
    private ExprValue minResult;
47
48
    MinState() {
49
      minResult = LITERAL_NULL;
50
    }
51
52
    public void min(ExprValue value) {
53 1 1. min : negated conditional → KILLED
      minResult = minResult.isNull() ? value
54 2 1. min : changed conditional boundary → SURVIVED
2. min : negated conditional → KILLED
          : (minResult.compareTo(value) < 0)
55
          ? minResult : value;
56
    }
57
58
    @Override
59
    public ExprValue result() {
60 1 1. result : replaced return value with null for org/opensearch/sql/expression/aggregation/MinAggregator$MinState::result → KILLED
      return minResult;
61
    }
62
  }
63
}

Mutations

31

1.1
Location : create
Killed by : org.opensearch.sql.expression.aggregation.MinAggregatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.aggregation.MinAggregatorTest]/[method:test_min_all_missing_or_null()]
replaced return value with null for org/opensearch/sql/expression/aggregation/MinAggregator::create → KILLED

36

1.1
Location : iterate
Killed by : org.opensearch.sql.expression.aggregation.MinAggregatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.aggregation.MinAggregatorTest]/[method:test_min_float()]
removed call to org/opensearch/sql/expression/aggregation/MinAggregator$MinState::min → KILLED

37

1.1
Location : iterate
Killed by : none
replaced return value with null for org/opensearch/sql/expression/aggregation/MinAggregator::iterate → SURVIVED

42

1.1
Location : toString
Killed by : org.opensearch.sql.expression.aggregation.MinAggregatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.aggregation.MinAggregatorTest]/[method:test_to_string()]
replaced return value with "" for org/opensearch/sql/expression/aggregation/MinAggregator::toString → KILLED

53

1.1
Location : min
Killed by : org.opensearch.sql.expression.aggregation.MinAggregatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.aggregation.MinAggregatorTest]/[method:test_min_float()]
negated conditional → KILLED

54

1.1
Location : min
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : min
Killed by : org.opensearch.sql.expression.aggregation.MinAggregatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.aggregation.MinAggregatorTest]/[method:test_min_float()]
negated conditional → KILLED

60

1.1
Location : result
Killed by : org.opensearch.sql.expression.aggregation.MinAggregatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.aggregation.MinAggregatorTest]/[method:test_min_all_missing_or_null()]
replaced return value with null for org/opensearch/sql/expression/aggregation/MinAggregator$MinState::result → KILLED

Active mutators

Tests examined


Report generated by PIT 1.9.0