33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6+
67package org .opensearch .sql .expression .aggregation ;
78
89import static org .opensearch .sql .data .type .ExprCoreType .ARRAY ;
@@ -65,37 +66,26 @@ private static DefaultFunctionResolver avg() {
6566 return new DefaultFunctionResolver (
6667 functionName ,
6768 new ImmutableMap .Builder <FunctionSignature , FunctionBuilder >()
68- .put (
69- new FunctionSignature (functionName , Collections .singletonList (DOUBLE )),
69+ .put (new FunctionSignature (functionName , Collections .singletonList (DOUBLE )),
7070 (functionProperties , arguments ) -> new AvgAggregator (arguments , DOUBLE ))
71- .put (
72- new FunctionSignature (functionName , Collections .singletonList (DATE )),
71+ .put (new FunctionSignature (functionName , Collections .singletonList (DATE )),
7372 (functionProperties , arguments ) -> new AvgAggregator (arguments , DATE ))
74- .put (
75- new FunctionSignature (functionName , Collections .singletonList (DATETIME )),
73+ .put (new FunctionSignature (functionName , Collections .singletonList (DATETIME )),
7674 (functionProperties , arguments ) -> new AvgAggregator (arguments , DATETIME ))
77- .put (
78- new FunctionSignature (functionName , Collections .singletonList (TIME )),
75+ .put (new FunctionSignature (functionName , Collections .singletonList (TIME )),
7976 (functionProperties , arguments ) -> new AvgAggregator (arguments , TIME ))
80- .put (
81- new FunctionSignature (functionName , Collections .singletonList (TIMESTAMP )),
77+ .put (new FunctionSignature (functionName , Collections .singletonList (TIMESTAMP )),
8278 (functionProperties , arguments ) -> new AvgAggregator (arguments , TIMESTAMP ))
83- .build ());
79+ .build ()
80+ );
8481 }
8582
8683 private static DefaultFunctionResolver count () {
8784 FunctionName functionName = BuiltinFunctionName .COUNT .getName ();
88- DefaultFunctionResolver functionResolver =
89- new DefaultFunctionResolver (
90- functionName ,
91- ExprCoreType .coreTypes ().stream ()
92- .collect (
93- Collectors .toMap (
94- type ->
95- new FunctionSignature (functionName , Collections .singletonList (type )),
96- type ->
97- (functionProperties , arguments ) ->
98- new CountAggregator (arguments , INTEGER ))));
85+ DefaultFunctionResolver functionResolver = new DefaultFunctionResolver (functionName ,
86+ ExprCoreType .coreTypes ().stream ().collect (Collectors .toMap (
87+ type -> new FunctionSignature (functionName , Collections .singletonList (type )),
88+ type -> (functionProperties , arguments ) -> new CountAggregator (arguments , INTEGER ))));
9989 return functionResolver ;
10090 }
10191
@@ -104,52 +94,40 @@ private static DefaultFunctionResolver sum() {
10494 return new DefaultFunctionResolver (
10595 functionName ,
10696 new ImmutableMap .Builder <FunctionSignature , FunctionBuilder >()
107- .put (
108- new FunctionSignature (functionName , Collections .singletonList (INTEGER )),
97+ .put (new FunctionSignature (functionName , Collections .singletonList (INTEGER )),
10998 (functionProperties , arguments ) -> new SumAggregator (arguments , INTEGER ))
110- .put (
111- new FunctionSignature (functionName , Collections .singletonList (LONG )),
99+ .put (new FunctionSignature (functionName , Collections .singletonList (LONG )),
112100 (functionProperties , arguments ) -> new SumAggregator (arguments , LONG ))
113- .put (
114- new FunctionSignature (functionName , Collections .singletonList (FLOAT )),
101+ .put (new FunctionSignature (functionName , Collections .singletonList (FLOAT )),
115102 (functionProperties , arguments ) -> new SumAggregator (arguments , FLOAT ))
116- .put (
117- new FunctionSignature (functionName , Collections .singletonList (DOUBLE )),
103+ .put (new FunctionSignature (functionName , Collections .singletonList (DOUBLE )),
118104 (functionProperties , arguments ) -> new SumAggregator (arguments , DOUBLE ))
119- .build ());
105+ .build ()
106+ );
120107 }
121108
122109 private static DefaultFunctionResolver min () {
123110 FunctionName functionName = BuiltinFunctionName .MIN .getName ();
124111 return new DefaultFunctionResolver (
125112 functionName ,
126113 new ImmutableMap .Builder <FunctionSignature , FunctionBuilder >()
127- .put (
128- new FunctionSignature (functionName , Collections .singletonList (INTEGER )),
114+ .put (new FunctionSignature (functionName , Collections .singletonList (INTEGER )),
129115 (functionProperties , arguments ) -> new MinAggregator (arguments , INTEGER ))
130- .put (
131- new FunctionSignature (functionName , Collections .singletonList (LONG )),
116+ .put (new FunctionSignature (functionName , Collections .singletonList (LONG )),
132117 (functionProperties , arguments ) -> new MinAggregator (arguments , LONG ))
133- .put (
134- new FunctionSignature (functionName , Collections .singletonList (FLOAT )),
118+ .put (new FunctionSignature (functionName , Collections .singletonList (FLOAT )),
135119 (functionProperties , arguments ) -> new MinAggregator (arguments , FLOAT ))
136- .put (
137- new FunctionSignature (functionName , Collections .singletonList (DOUBLE )),
120+ .put (new FunctionSignature (functionName , Collections .singletonList (DOUBLE )),
138121 (functionProperties , arguments ) -> new MinAggregator (arguments , DOUBLE ))
139- .put (
140- new FunctionSignature (functionName , Collections .singletonList (STRING )),
122+ .put (new FunctionSignature (functionName , Collections .singletonList (STRING )),
141123 (functionProperties , arguments ) -> new MinAggregator (arguments , STRING ))
142- .put (
143- new FunctionSignature (functionName , Collections .singletonList (DATE )),
124+ .put (new FunctionSignature (functionName , Collections .singletonList (DATE )),
144125 (functionProperties , arguments ) -> new MinAggregator (arguments , DATE ))
145- .put (
146- new FunctionSignature (functionName , Collections .singletonList (DATETIME )),
126+ .put (new FunctionSignature (functionName , Collections .singletonList (DATETIME )),
147127 (functionProperties , arguments ) -> new MinAggregator (arguments , DATETIME ))
148- .put (
149- new FunctionSignature (functionName , Collections .singletonList (TIME )),
128+ .put (new FunctionSignature (functionName , Collections .singletonList (TIME )),
150129 (functionProperties , arguments ) -> new MinAggregator (arguments , TIME ))
151- .put (
152- new FunctionSignature (functionName , Collections .singletonList (TIMESTAMP )),
130+ .put (new FunctionSignature (functionName , Collections .singletonList (TIMESTAMP )),
153131 (functionProperties , arguments ) -> new MinAggregator (arguments , TIMESTAMP ))
154132 .build ());
155133 }
@@ -159,90 +137,80 @@ private static DefaultFunctionResolver max() {
159137 return new DefaultFunctionResolver (
160138 functionName ,
161139 new ImmutableMap .Builder <FunctionSignature , FunctionBuilder >()
162- .put (
163- new FunctionSignature (functionName , Collections .singletonList (INTEGER )),
140+ .put (new FunctionSignature (functionName , Collections .singletonList (INTEGER )),
164141 (functionProperties , arguments ) -> new MaxAggregator (arguments , INTEGER ))
165- .put (
166- new FunctionSignature (functionName , Collections .singletonList (LONG )),
142+ .put (new FunctionSignature (functionName , Collections .singletonList (LONG )),
167143 (functionProperties , arguments ) -> new MaxAggregator (arguments , LONG ))
168- .put (
169- new FunctionSignature (functionName , Collections .singletonList (FLOAT )),
144+ .put (new FunctionSignature (functionName , Collections .singletonList (FLOAT )),
170145 (functionProperties , arguments ) -> new MaxAggregator (arguments , FLOAT ))
171- .put (
172- new FunctionSignature (functionName , Collections .singletonList (DOUBLE )),
146+ .put (new FunctionSignature (functionName , Collections .singletonList (DOUBLE )),
173147 (functionProperties , arguments ) -> new MaxAggregator (arguments , DOUBLE ))
174- .put (
175- new FunctionSignature (functionName , Collections .singletonList (STRING )),
148+ .put (new FunctionSignature (functionName , Collections .singletonList (STRING )),
176149 (functionProperties , arguments ) -> new MaxAggregator (arguments , STRING ))
177- .put (
178- new FunctionSignature (functionName , Collections .singletonList (DATE )),
150+ .put (new FunctionSignature (functionName , Collections .singletonList (DATE )),
179151 (functionProperties , arguments ) -> new MaxAggregator (arguments , DATE ))
180- .put (
181- new FunctionSignature (functionName , Collections .singletonList (DATETIME )),
152+ .put (new FunctionSignature (functionName , Collections .singletonList (DATETIME )),
182153 (functionProperties , arguments ) -> new MaxAggregator (arguments , DATETIME ))
183- .put (
184- new FunctionSignature (functionName , Collections .singletonList (TIME )),
154+ .put (new FunctionSignature (functionName , Collections .singletonList (TIME )),
185155 (functionProperties , arguments ) -> new MaxAggregator (arguments , TIME ))
186- .put (
187- new FunctionSignature (functionName , Collections .singletonList (TIMESTAMP )),
156+ .put (new FunctionSignature (functionName , Collections .singletonList (TIMESTAMP )),
188157 (functionProperties , arguments ) -> new MaxAggregator (arguments , TIMESTAMP ))
189- .build ());
158+ .build ()
159+ );
190160 }
191161
192162 private static DefaultFunctionResolver varSamp () {
193163 FunctionName functionName = BuiltinFunctionName .VARSAMP .getName ();
194164 return new DefaultFunctionResolver (
195165 functionName ,
196166 new ImmutableMap .Builder <FunctionSignature , FunctionBuilder >()
197- .put (
198- new FunctionSignature (functionName , Collections .singletonList (DOUBLE )),
167+ .put (new FunctionSignature (functionName , Collections .singletonList (DOUBLE )),
199168 (functionProperties , arguments ) -> varianceSample (arguments , DOUBLE ))
200- .build ());
169+ .build ()
170+ );
201171 }
202172
203173 private static DefaultFunctionResolver varPop () {
204174 FunctionName functionName = BuiltinFunctionName .VARPOP .getName ();
205175 return new DefaultFunctionResolver (
206176 functionName ,
207177 new ImmutableMap .Builder <FunctionSignature , FunctionBuilder >()
208- .put (
209- new FunctionSignature (functionName , Collections .singletonList (DOUBLE )),
178+ .put (new FunctionSignature (functionName , Collections .singletonList (DOUBLE )),
210179 (functionProperties , arguments ) -> variancePopulation (arguments , DOUBLE ))
211- .build ());
180+ .build ()
181+ );
212182 }
213183
214184 private static DefaultFunctionResolver stddevSamp () {
215185 FunctionName functionName = BuiltinFunctionName .STDDEV_SAMP .getName ();
216186 return new DefaultFunctionResolver (
217187 functionName ,
218188 new ImmutableMap .Builder <FunctionSignature , FunctionBuilder >()
219- .put (
220- new FunctionSignature (functionName , Collections .singletonList (DOUBLE )),
189+ .put (new FunctionSignature (functionName , Collections .singletonList (DOUBLE )),
221190 (functionProperties , arguments ) -> stddevSample (arguments , DOUBLE ))
222- .build ());
191+ .build ()
192+ );
223193 }
224194
225195 private static DefaultFunctionResolver stddevPop () {
226196 FunctionName functionName = BuiltinFunctionName .STDDEV_POP .getName ();
227197 return new DefaultFunctionResolver (
228198 functionName ,
229199 new ImmutableMap .Builder <FunctionSignature , FunctionBuilder >()
230- .put (
231- new FunctionSignature (functionName , Collections .singletonList (DOUBLE )),
200+ .put (new FunctionSignature (functionName , Collections .singletonList (DOUBLE )),
232201 (functionProperties , arguments ) -> stddevPopulation (arguments , DOUBLE ))
233- .build ());
202+ .build ()
203+ );
234204 }
235205
236206 private static DefaultFunctionResolver take () {
237207 FunctionName functionName = BuiltinFunctionName .TAKE .getName ();
238- DefaultFunctionResolver functionResolver =
239- new DefaultFunctionResolver (
240- functionName ,
241- new ImmutableMap .Builder <FunctionSignature , FunctionBuilder >()
242- .put (
243- new FunctionSignature (functionName , ImmutableList .of (STRING , INTEGER )),
244- (functionProperties , arguments ) -> new TakeAggregator (arguments , ARRAY ))
245- .build ());
208+ DefaultFunctionResolver functionResolver = new DefaultFunctionResolver (functionName ,
209+ new ImmutableMap .Builder <FunctionSignature , FunctionBuilder >()
210+ .put (new FunctionSignature (functionName , ImmutableList .of (STRING , INTEGER )),
211+ (functionProperties , arguments ) -> new TakeAggregator (arguments , ARRAY ))
212+ .build ());
246213 return functionResolver ;
247214 }
215+
248216}
0 commit comments