1 | /* | |
2 | * Copyright OpenSearch Contributors | |
3 | * SPDX-License-Identifier: Apache-2.0 | |
4 | */ | |
5 | ||
6 | ||
7 | package org.opensearch.sql.expression.aggregation; | |
8 | ||
9 | import static org.opensearch.sql.data.type.ExprCoreType.ARRAY; | |
10 | import static org.opensearch.sql.data.type.ExprCoreType.DATE; | |
11 | import static org.opensearch.sql.data.type.ExprCoreType.DATETIME; | |
12 | import static org.opensearch.sql.data.type.ExprCoreType.DOUBLE; | |
13 | import static org.opensearch.sql.data.type.ExprCoreType.FLOAT; | |
14 | import static org.opensearch.sql.data.type.ExprCoreType.INTEGER; | |
15 | import static org.opensearch.sql.data.type.ExprCoreType.LONG; | |
16 | import static org.opensearch.sql.data.type.ExprCoreType.STRING; | |
17 | import static org.opensearch.sql.data.type.ExprCoreType.TIME; | |
18 | import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP; | |
19 | import static org.opensearch.sql.expression.aggregation.StdDevAggregator.stddevPopulation; | |
20 | import static org.opensearch.sql.expression.aggregation.StdDevAggregator.stddevSample; | |
21 | import static org.opensearch.sql.expression.aggregation.VarianceAggregator.variancePopulation; | |
22 | import static org.opensearch.sql.expression.aggregation.VarianceAggregator.varianceSample; | |
23 | ||
24 | import com.google.common.collect.ImmutableList; | |
25 | import com.google.common.collect.ImmutableMap; | |
26 | import java.util.Collections; | |
27 | import java.util.stream.Collectors; | |
28 | import lombok.experimental.UtilityClass; | |
29 | import org.opensearch.sql.data.type.ExprCoreType; | |
30 | import org.opensearch.sql.expression.function.BuiltinFunctionName; | |
31 | import org.opensearch.sql.expression.function.BuiltinFunctionRepository; | |
32 | import org.opensearch.sql.expression.function.DefaultFunctionResolver; | |
33 | import org.opensearch.sql.expression.function.FunctionBuilder; | |
34 | import org.opensearch.sql.expression.function.FunctionName; | |
35 | import org.opensearch.sql.expression.function.FunctionSignature; | |
36 | ||
37 | /** | |
38 | * The definition of aggregator function | |
39 | * avg, Accepts two numbers and produces a number. | |
40 | * sum, Accepts two numbers and produces a number. | |
41 | * max, Accepts two numbers and produces a number. | |
42 | * min, Accepts two numbers and produces a number. | |
43 | * count, Accepts two numbers and produces a number. | |
44 | */ | |
45 | @UtilityClass | |
46 | public class AggregatorFunction { | |
47 | /** | |
48 | * Register Aggregation Function. | |
49 | * | |
50 | * @param repository {@link BuiltinFunctionRepository}. | |
51 | */ | |
52 | public static void register(BuiltinFunctionRepository repository) { | |
53 |
1
1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → KILLED |
repository.register(avg()); |
54 |
1
1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → KILLED |
repository.register(sum()); |
55 |
1
1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → KILLED |
repository.register(count()); |
56 |
1
1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → KILLED |
repository.register(min()); |
57 |
1
1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED |
repository.register(max()); |
58 |
1
1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED |
repository.register(varSamp()); |
59 |
1
1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED |
repository.register(varPop()); |
60 |
1
1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED |
repository.register(stddevSamp()); |
61 |
1
1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED |
repository.register(stddevPop()); |
62 |
1
1. register : removed call to org/opensearch/sql/expression/function/BuiltinFunctionRepository::register → SURVIVED |
repository.register(take()); |
63 | } | |
64 | ||
65 | private static DefaultFunctionResolver avg() { | |
66 | FunctionName functionName = BuiltinFunctionName.AVG.getName(); | |
67 |
1
1. avg : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::avg → KILLED |
return new DefaultFunctionResolver( |
68 | functionName, | |
69 | new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>() | |
70 | .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), | |
71 |
1
1. lambda$avg$0 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$avg$0 → KILLED |
arguments -> new AvgAggregator(arguments, DOUBLE)) |
72 | .build() | |
73 | ); | |
74 | } | |
75 | ||
76 | private static DefaultFunctionResolver count() { | |
77 | FunctionName functionName = BuiltinFunctionName.COUNT.getName(); | |
78 | DefaultFunctionResolver functionResolver = new DefaultFunctionResolver(functionName, | |
79 | ExprCoreType.coreTypes().stream().collect(Collectors.toMap( | |
80 |
1
1. lambda$count$1 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$count$1 → KILLED |
type -> new FunctionSignature(functionName, Collections.singletonList(type)), |
81 |
2
1. lambda$count$2 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$count$2 → KILLED 2. lambda$count$3 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$count$3 → KILLED |
type -> arguments -> new CountAggregator(arguments, INTEGER)))); |
82 |
1
1. count : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::count → KILLED |
return functionResolver; |
83 | } | |
84 | ||
85 | private static DefaultFunctionResolver sum() { | |
86 | FunctionName functionName = BuiltinFunctionName.SUM.getName(); | |
87 |
1
1. sum : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::sum → KILLED |
return new DefaultFunctionResolver( |
88 | functionName, | |
89 | new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>() | |
90 | .put(new FunctionSignature(functionName, Collections.singletonList(INTEGER)), | |
91 |
1
1. lambda$sum$4 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$sum$4 → KILLED |
arguments -> new SumAggregator(arguments, INTEGER)) |
92 | .put(new FunctionSignature(functionName, Collections.singletonList(LONG)), | |
93 |
1
1. lambda$sum$5 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$sum$5 → KILLED |
arguments -> new SumAggregator(arguments, LONG)) |
94 | .put(new FunctionSignature(functionName, Collections.singletonList(FLOAT)), | |
95 |
1
1. lambda$sum$6 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$sum$6 → KILLED |
arguments -> new SumAggregator(arguments, FLOAT)) |
96 | .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), | |
97 |
1
1. lambda$sum$7 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$sum$7 → KILLED |
arguments -> new SumAggregator(arguments, DOUBLE)) |
98 | .build() | |
99 | ); | |
100 | } | |
101 | ||
102 | private static DefaultFunctionResolver min() { | |
103 | FunctionName functionName = BuiltinFunctionName.MIN.getName(); | |
104 |
1
1. min : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::min → KILLED |
return new DefaultFunctionResolver( |
105 | functionName, | |
106 | new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>() | |
107 | .put(new FunctionSignature(functionName, Collections.singletonList(INTEGER)), | |
108 |
1
1. lambda$min$8 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$min$8 → KILLED |
arguments -> new MinAggregator(arguments, INTEGER)) |
109 | .put(new FunctionSignature(functionName, Collections.singletonList(LONG)), | |
110 |
1
1. lambda$min$9 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$min$9 → KILLED |
arguments -> new MinAggregator(arguments, LONG)) |
111 | .put(new FunctionSignature(functionName, Collections.singletonList(FLOAT)), | |
112 |
1
1. lambda$min$10 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$min$10 → KILLED |
arguments -> new MinAggregator(arguments, FLOAT)) |
113 | .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), | |
114 |
1
1. lambda$min$11 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$min$11 → KILLED |
arguments -> new MinAggregator(arguments, DOUBLE)) |
115 | .put(new FunctionSignature(functionName, Collections.singletonList(STRING)), | |
116 |
1
1. lambda$min$12 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$min$12 → KILLED |
arguments -> new MinAggregator(arguments, STRING)) |
117 | .put(new FunctionSignature(functionName, Collections.singletonList(DATE)), | |
118 |
1
1. lambda$min$13 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$min$13 → KILLED |
arguments -> new MinAggregator(arguments, DATE)) |
119 | .put(new FunctionSignature(functionName, Collections.singletonList(DATETIME)), | |
120 |
1
1. lambda$min$14 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$min$14 → KILLED |
arguments -> new MinAggregator(arguments, DATETIME)) |
121 | .put(new FunctionSignature(functionName, Collections.singletonList(TIME)), | |
122 |
1
1. lambda$min$15 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$min$15 → KILLED |
arguments -> new MinAggregator(arguments, TIME)) |
123 | .put(new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)), | |
124 |
1
1. lambda$min$16 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$min$16 → KILLED |
arguments -> new MinAggregator(arguments, TIMESTAMP)) |
125 | .build()); | |
126 | } | |
127 | ||
128 | private static DefaultFunctionResolver max() { | |
129 | FunctionName functionName = BuiltinFunctionName.MAX.getName(); | |
130 |
1
1. max : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::max → KILLED |
return new DefaultFunctionResolver( |
131 | functionName, | |
132 | new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>() | |
133 | .put(new FunctionSignature(functionName, Collections.singletonList(INTEGER)), | |
134 |
1
1. lambda$max$17 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$max$17 → KILLED |
arguments -> new MaxAggregator(arguments, INTEGER)) |
135 | .put(new FunctionSignature(functionName, Collections.singletonList(LONG)), | |
136 |
1
1. lambda$max$18 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$max$18 → KILLED |
arguments -> new MaxAggregator(arguments, LONG)) |
137 | .put(new FunctionSignature(functionName, Collections.singletonList(FLOAT)), | |
138 |
1
1. lambda$max$19 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$max$19 → KILLED |
arguments -> new MaxAggregator(arguments, FLOAT)) |
139 | .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), | |
140 |
1
1. lambda$max$20 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$max$20 → KILLED |
arguments -> new MaxAggregator(arguments, DOUBLE)) |
141 | .put(new FunctionSignature(functionName, Collections.singletonList(STRING)), | |
142 |
1
1. lambda$max$21 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$max$21 → KILLED |
arguments -> new MaxAggregator(arguments, STRING)) |
143 | .put(new FunctionSignature(functionName, Collections.singletonList(DATE)), | |
144 |
1
1. lambda$max$22 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$max$22 → KILLED |
arguments -> new MaxAggregator(arguments, DATE)) |
145 | .put(new FunctionSignature(functionName, Collections.singletonList(DATETIME)), | |
146 |
1
1. lambda$max$23 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$max$23 → KILLED |
arguments -> new MaxAggregator(arguments, DATETIME)) |
147 | .put(new FunctionSignature(functionName, Collections.singletonList(TIME)), | |
148 |
1
1. lambda$max$24 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$max$24 → KILLED |
arguments -> new MaxAggregator(arguments, TIME)) |
149 | .put(new FunctionSignature(functionName, Collections.singletonList(TIMESTAMP)), | |
150 |
1
1. lambda$max$25 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$max$25 → KILLED |
arguments -> new MaxAggregator(arguments, TIMESTAMP)) |
151 | .build() | |
152 | ); | |
153 | } | |
154 | ||
155 | private static DefaultFunctionResolver varSamp() { | |
156 | FunctionName functionName = BuiltinFunctionName.VARSAMP.getName(); | |
157 |
1
1. varSamp : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::varSamp → KILLED |
return new DefaultFunctionResolver( |
158 | functionName, | |
159 | new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>() | |
160 | .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), | |
161 |
1
1. lambda$varSamp$26 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$varSamp$26 → KILLED |
arguments -> varianceSample(arguments, DOUBLE)) |
162 | .build() | |
163 | ); | |
164 | } | |
165 | ||
166 | private static DefaultFunctionResolver varPop() { | |
167 | FunctionName functionName = BuiltinFunctionName.VARPOP.getName(); | |
168 |
1
1. varPop : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::varPop → KILLED |
return new DefaultFunctionResolver( |
169 | functionName, | |
170 | new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>() | |
171 | .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), | |
172 |
1
1. lambda$varPop$27 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$varPop$27 → KILLED |
arguments -> variancePopulation(arguments, DOUBLE)) |
173 | .build() | |
174 | ); | |
175 | } | |
176 | ||
177 | private static DefaultFunctionResolver stddevSamp() { | |
178 | FunctionName functionName = BuiltinFunctionName.STDDEV_SAMP.getName(); | |
179 |
1
1. stddevSamp : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::stddevSamp → KILLED |
return new DefaultFunctionResolver( |
180 | functionName, | |
181 | new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>() | |
182 | .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), | |
183 |
1
1. lambda$stddevSamp$28 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$stddevSamp$28 → KILLED |
arguments -> stddevSample(arguments, DOUBLE)) |
184 | .build() | |
185 | ); | |
186 | } | |
187 | ||
188 | private static DefaultFunctionResolver stddevPop() { | |
189 | FunctionName functionName = BuiltinFunctionName.STDDEV_POP.getName(); | |
190 |
1
1. stddevPop : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::stddevPop → KILLED |
return new DefaultFunctionResolver( |
191 | functionName, | |
192 | new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>() | |
193 | .put(new FunctionSignature(functionName, Collections.singletonList(DOUBLE)), | |
194 |
1
1. lambda$stddevPop$29 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$stddevPop$29 → KILLED |
arguments -> stddevPopulation(arguments, DOUBLE)) |
195 | .build() | |
196 | ); | |
197 | } | |
198 | ||
199 | private static DefaultFunctionResolver take() { | |
200 | FunctionName functionName = BuiltinFunctionName.TAKE.getName(); | |
201 | DefaultFunctionResolver functionResolver = new DefaultFunctionResolver(functionName, | |
202 | new ImmutableMap.Builder<FunctionSignature, FunctionBuilder>() | |
203 | .put(new FunctionSignature(functionName, ImmutableList.of(STRING, INTEGER)), | |
204 |
1
1. lambda$take$30 : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::lambda$take$30 → KILLED |
arguments -> new TakeAggregator(arguments, ARRAY)) |
205 | .build()); | |
206 |
1
1. take : replaced return value with null for org/opensearch/sql/expression/aggregation/AggregatorFunction::take → KILLED |
return functionResolver; |
207 | } | |
208 | ||
209 | } | |
Mutations | ||
53 |
1.1 |
|
54 |
1.1 |
|
55 |
1.1 |
|
56 |
1.1 |
|
57 |
1.1 |
|
58 |
1.1 |
|
59 |
1.1 |
|
60 |
1.1 |
|
61 |
1.1 |
|
62 |
1.1 |
|
67 |
1.1 |
|
71 |
1.1 |
|
80 |
1.1 |
|
81 |
1.1 2.2 |
|
82 |
1.1 |
|
87 |
1.1 |
|
91 |
1.1 |
|
93 |
1.1 |
|
95 |
1.1 |
|
97 |
1.1 |
|
104 |
1.1 |
|
108 |
1.1 |
|
110 |
1.1 |
|
112 |
1.1 |
|
114 |
1.1 |
|
116 |
1.1 |
|
118 |
1.1 |
|
120 |
1.1 |
|
122 |
1.1 |
|
124 |
1.1 |
|
130 |
1.1 |
|
134 |
1.1 |
|
136 |
1.1 |
|
138 |
1.1 |
|
140 |
1.1 |
|
142 |
1.1 |
|
144 |
1.1 |
|
146 |
1.1 |
|
148 |
1.1 |
|
150 |
1.1 |
|
157 |
1.1 |
|
161 |
1.1 |
|
168 |
1.1 |
|
172 |
1.1 |
|
179 |
1.1 |
|
183 |
1.1 |
|
190 |
1.1 |
|
194 |
1.1 |
|
204 |
1.1 |
|
206 |
1.1 |