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 |
|
34 |
1.1 |
|
35 |
1.1 |
|
39 |
1.1 |