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 |
|
42 |
1.1 |
|
50 |
1.1 |
|
55 |
1.1 |
|
60 |
1.1 |
|
65 |
1.1 |