AggregateWindowFunction.java

1
/*
2
 * Copyright OpenSearch Contributors
3
 * SPDX-License-Identifier: Apache-2.0
4
 */
5
6
7
package org.opensearch.sql.expression.window.aggregation;
8
9
import java.util.List;
10
import lombok.EqualsAndHashCode;
11
import lombok.RequiredArgsConstructor;
12
import org.opensearch.sql.data.model.ExprValue;
13
import org.opensearch.sql.data.type.ExprType;
14
import org.opensearch.sql.expression.Expression;
15
import org.opensearch.sql.expression.ExpressionNodeVisitor;
16
import org.opensearch.sql.expression.aggregation.AggregationState;
17
import org.opensearch.sql.expression.aggregation.Aggregator;
18
import org.opensearch.sql.expression.env.Environment;
19
import org.opensearch.sql.expression.window.WindowDefinition;
20
import org.opensearch.sql.expression.window.WindowFunctionExpression;
21
import org.opensearch.sql.expression.window.frame.PeerRowsWindowFrame;
22
import org.opensearch.sql.expression.window.frame.WindowFrame;
23
24
/**
25
 * Aggregate function adapter that adapts Aggregator for window operator use.
26
 */
27
@EqualsAndHashCode
28
@RequiredArgsConstructor
29
public class AggregateWindowFunction implements WindowFunctionExpression {
30
31
  private final Aggregator<AggregationState> aggregator;
32
  private AggregationState state;
33
34
  @Override
35
  public WindowFrame createWindowFrame(WindowDefinition definition) {
36 1 1. createWindowFrame : replaced return value with null for org/opensearch/sql/expression/window/aggregation/AggregateWindowFunction::createWindowFrame → KILLED
    return new PeerRowsWindowFrame(definition);
37
  }
38
39
  @Override
40
  public ExprValue valueOf(Environment<Expression, ExprValue> valueEnv) {
41
    PeerRowsWindowFrame frame = (PeerRowsWindowFrame) valueEnv;
42 1 1. valueOf : negated conditional → KILLED
    if (frame.isNewPartition()) {
43
      state = aggregator.create();
44
    }
45
46
    List<ExprValue> peers = frame.next();
47
    for (ExprValue peer : peers) {
48
      state = aggregator.iterate(peer.bindingTuples(), state);
49
    }
50 1 1. valueOf : replaced return value with null for org/opensearch/sql/expression/window/aggregation/AggregateWindowFunction::valueOf → KILLED
    return state.result();
51
  }
52
53
  @Override
54
  public ExprType type() {
55 1 1. type : replaced return value with null for org/opensearch/sql/expression/window/aggregation/AggregateWindowFunction::type → KILLED
    return aggregator.type();
56
  }
57
58
  @Override
59
  public <T, C> T accept(ExpressionNodeVisitor<T, C> visitor, C context) {
60 1 1. accept : replaced return value with null for org/opensearch/sql/expression/window/aggregation/AggregateWindowFunction::accept → KILLED
    return aggregator.accept(visitor, context);
61
  }
62
63
  @Override
64
  public String toString() {
65 1 1. toString : replaced return value with "" for org/opensearch/sql/expression/window/aggregation/AggregateWindowFunction::toString → KILLED
    return aggregator.toString();
66
  }
67
68
}

Mutations

36

1.1
Location : createWindowFrame
Killed by : org.opensearch.sql.planner.physical.WindowOperatorTest.[engine:junit-jupiter]/[class:org.opensearch.sql.planner.physical.WindowOperatorTest]/[method:test_aggregate_window_function_without_sort_key()]
replaced return value with null for org/opensearch/sql/expression/window/aggregation/AggregateWindowFunction::createWindowFrame → KILLED

42

1.1
Location : valueOf
Killed by : org.opensearch.sql.expression.window.aggregation.AggregateWindowFunctionTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.window.aggregation.AggregateWindowFunctionTest]/[method:should_accumulate_all_peer_values_and_not_reset_state_if_same_partition()]
negated conditional → KILLED

50

1.1
Location : valueOf
Killed by : org.opensearch.sql.expression.window.aggregation.AggregateWindowFunctionTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.window.aggregation.AggregateWindowFunctionTest]/[method:should_accumulate_all_peer_values_and_not_reset_state_if_same_partition()]
replaced return value with null for org/opensearch/sql/expression/window/aggregation/AggregateWindowFunction::valueOf → KILLED

55

1.1
Location : type
Killed by : org.opensearch.sql.expression.window.aggregation.AggregateWindowFunctionTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.window.aggregation.AggregateWindowFunctionTest]/[method:test_delegated_methods()]
replaced return value with null for org/opensearch/sql/expression/window/aggregation/AggregateWindowFunction::type → KILLED

60

1.1
Location : accept
Killed by : org.opensearch.sql.expression.window.aggregation.AggregateWindowFunctionTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.window.aggregation.AggregateWindowFunctionTest]/[method:test_delegated_methods()]
replaced return value with null for org/opensearch/sql/expression/window/aggregation/AggregateWindowFunction::accept → KILLED

65

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

Active mutators

Tests examined


Report generated by PIT 1.9.0