1 | /* | |
2 | * Copyright OpenSearch Contributors | |
3 | * SPDX-License-Identifier: Apache-2.0 | |
4 | */ | |
5 | ||
6 | ||
7 | package org.opensearch.sql.expression.window.frame; | |
8 | ||
9 | import com.google.common.collect.PeekingIterator; | |
10 | import java.util.Collections; | |
11 | import java.util.List; | |
12 | import java.util.Objects; | |
13 | import java.util.stream.Collectors; | |
14 | import lombok.EqualsAndHashCode; | |
15 | import lombok.Getter; | |
16 | import lombok.RequiredArgsConstructor; | |
17 | import lombok.ToString; | |
18 | import org.opensearch.sql.data.model.ExprValue; | |
19 | import org.opensearch.sql.expression.Expression; | |
20 | import org.opensearch.sql.expression.env.Environment; | |
21 | import org.opensearch.sql.expression.window.WindowDefinition; | |
22 | ||
23 | /** | |
24 | * Conceptually, cumulative window frame should hold all seen rows till next partition. | |
25 | * This class is actually an optimized version that only hold previous and current row. This is | |
26 | * efficient and sufficient for ranking and aggregate window function support for now, though need | |
27 | * to add "real" cumulative frame implementation in future as needed. | |
28 | */ | |
29 | @EqualsAndHashCode | |
30 | @RequiredArgsConstructor | |
31 | @ToString | |
32 | public class CurrentRowWindowFrame implements WindowFrame { | |
33 | ||
34 | @Getter | |
35 | private final WindowDefinition windowDefinition; | |
36 | ||
37 | private ExprValue previous; | |
38 | private ExprValue current; | |
39 | ||
40 | @Override | |
41 | public boolean isNewPartition() { | |
42 | Objects.requireNonNull(current); | |
43 | ||
44 |
1
1. isNewPartition : negated conditional → KILLED |
if (previous == null) { |
45 |
1
1. isNewPartition : replaced boolean return with false for org/opensearch/sql/expression/window/frame/CurrentRowWindowFrame::isNewPartition → KILLED |
return true; |
46 | } | |
47 | ||
48 | List<ExprValue> preValues = resolve(windowDefinition.getPartitionByList(), previous); | |
49 | List<ExprValue> curValues = resolve(windowDefinition.getPartitionByList(), current); | |
50 |
2
1. isNewPartition : negated conditional → KILLED 2. isNewPartition : replaced boolean return with true for org/opensearch/sql/expression/window/frame/CurrentRowWindowFrame::isNewPartition → KILLED |
return !preValues.equals(curValues); |
51 | } | |
52 | ||
53 | @Override | |
54 | public void load(PeekingIterator<ExprValue> it) { | |
55 | previous = current; | |
56 | current = it.next(); | |
57 | } | |
58 | ||
59 | @Override | |
60 | public ExprValue current() { | |
61 |
1
1. current : replaced return value with null for org/opensearch/sql/expression/window/frame/CurrentRowWindowFrame::current → KILLED |
return current; |
62 | } | |
63 | ||
64 | public ExprValue previous() { | |
65 |
1
1. previous : replaced return value with null for org/opensearch/sql/expression/window/frame/CurrentRowWindowFrame::previous → KILLED |
return previous; |
66 | } | |
67 | ||
68 | private List<ExprValue> resolve(List<Expression> expressions, ExprValue row) { | |
69 | Environment<Expression, ExprValue> valueEnv = row.bindingTuples(); | |
70 |
1
1. resolve : replaced return value with Collections.emptyList for org/opensearch/sql/expression/window/frame/CurrentRowWindowFrame::resolve → KILLED |
return expressions.stream() |
71 |
1
1. lambda$resolve$0 : replaced return value with null for org/opensearch/sql/expression/window/frame/CurrentRowWindowFrame::lambda$resolve$0 → KILLED |
.map(expr -> expr.valueOf(valueEnv)) |
72 | .collect(Collectors.toList()); | |
73 | } | |
74 | ||
75 | /** | |
76 | * Current row window frame won't pre-fetch any row ahead. | |
77 | * So always return false as nothing "cached" in frame. | |
78 | */ | |
79 | @Override | |
80 | public boolean hasNext() { | |
81 |
1
1. hasNext : replaced boolean return with true for org/opensearch/sql/expression/window/frame/CurrentRowWindowFrame::hasNext → KILLED |
return false; |
82 | } | |
83 | ||
84 | @Override | |
85 | public List<ExprValue> next() { | |
86 | return Collections.emptyList(); | |
87 | } | |
88 | ||
89 | } | |
Mutations | ||
44 |
1.1 |
|
45 |
1.1 |
|
50 |
1.1 2.2 |
|
61 |
1.1 |
|
65 |
1.1 |
|
70 |
1.1 |
|
71 |
1.1 |
|
81 |
1.1 |