RankFunction.java

1
/*
2
 * Copyright OpenSearch Contributors
3
 * SPDX-License-Identifier: Apache-2.0
4
 */
5
6
7
package org.opensearch.sql.expression.window.ranking;
8
9
import org.opensearch.sql.expression.function.BuiltinFunctionName;
10
import org.opensearch.sql.expression.window.frame.CurrentRowWindowFrame;
11
12
/**
13
 * Rank window function that assigns a rank number to each row based on sort items
14
 * defined in window definition. Use same rank number if sort item values same on
15
 * previous and current row.
16
 */
17
public class RankFunction extends RankingWindowFunction {
18
19
  /**
20
   * Total number of rows have seen in current partition.
21
   */
22
  private int total;
23
24
  public RankFunction() {
25
    super(BuiltinFunctionName.RANK.getName());
26
  }
27
28
  @Override
29
  protected int rank(CurrentRowWindowFrame frame) {
30 1 1. rank : negated conditional → KILLED
    if (frame.isNewPartition()) {
31
      total = 1;
32
      rank = 1;
33
    } else {
34 1 1. rank : Replaced integer addition with subtraction → KILLED
      total++;
35 1 1. rank : negated conditional → KILLED
      if (isSortFieldValueDifferent(frame)) {
36
        rank = total;
37
      }
38
    }
39 1 1. rank : replaced int return with 0 for org/opensearch/sql/expression/window/ranking/RankFunction::rank → KILLED
    return rank;
40
  }
41
42
}

Mutations

30

1.1
Location : rank
Killed by : org.opensearch.sql.expression.window.ranking.RankingWindowFunctionTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.window.ranking.RankingWindowFunctionTest]/[method:rank_should_always_return_1_if_no_sort_items_defined()]
negated conditional → KILLED

34

1.1
Location : rank
Killed by : org.opensearch.sql.expression.window.ranking.RankingWindowFunctionTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.window.ranking.RankingWindowFunctionTest]/[method:test_rank()]
Replaced integer addition with subtraction → KILLED

35

1.1
Location : rank
Killed by : org.opensearch.sql.expression.window.ranking.RankingWindowFunctionTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.window.ranking.RankingWindowFunctionTest]/[method:rank_should_always_return_1_if_no_sort_items_defined()]
negated conditional → KILLED

39

1.1
Location : rank
Killed by : org.opensearch.sql.expression.window.ranking.RankingWindowFunctionTest.[engine:junit-jupiter]/[class:org.opensearch.sql.expression.window.ranking.RankingWindowFunctionTest]/[method:rank_should_always_return_1_if_no_sort_items_defined()]
replaced int return with 0 for org/opensearch/sql/expression/window/ranking/RankFunction::rank → KILLED

Active mutators

Tests examined


Report generated by PIT 1.9.0