30
30
import org .elasticsearch .xpack .esql .expression .function .EsqlFunctionRegistry ;
31
31
import org .elasticsearch .xpack .esql .expression .function .FunctionInfo ;
32
32
import org .elasticsearch .xpack .esql .expression .function .Param ;
33
- import org .elasticsearch .xpack .esql .expression .function .aggregate .StdDev ;
34
33
import org .elasticsearch .xpack .esql .expression .function .scalar .EsqlScalarFunction ;
35
34
import org .elasticsearch .xpack .esql .io .stream .PlanStreamInput ;
36
35
import org .elasticsearch .xpack .esql .planner .PlannerUtils ;
@@ -84,7 +83,14 @@ public ConfidenceInterval(
84
83
}
85
84
86
85
private ConfidenceInterval (StreamInput in ) throws IOException {
87
- this (Source .readFrom ((PlanStreamInput ) in ), in .readNamedWriteable (Expression .class ), in .readNamedWriteable (Expression .class ), in .readNamedWriteable (Expression .class ), in .readNamedWriteable (Expression .class ), in .readNamedWriteable (Expression .class ));
86
+ this (
87
+ Source .readFrom ((PlanStreamInput ) in ),
88
+ in .readNamedWriteable (Expression .class ),
89
+ in .readNamedWriteable (Expression .class ),
90
+ in .readNamedWriteable (Expression .class ),
91
+ in .readNamedWriteable (Expression .class ),
92
+ in .readNamedWriteable (Expression .class )
93
+ );
88
94
}
89
95
90
96
@ Override
@@ -105,15 +111,20 @@ public String getWriteableName() {
105
111
@ Override
106
112
protected TypeResolution resolveType () {
107
113
return isType (bestEstimate , t -> t .isNumeric () && isRepresentable (t ), sourceText (), FIRST , "numeric" ).and (
108
- isType (estimates , t -> t .isNumeric () && isRepresentable (t ), sourceText (), SECOND , "numeric" )).and (
109
- isType (trialCount , t -> t == DataType .INTEGER , sourceText (), THIRD , "integer" )).and (
110
- isType (bucketCount , t -> t == DataType .INTEGER , sourceText (), FOURTH , "integer" )).and (
111
- isType (confidenceLevel , t -> t == DataType .DOUBLE , sourceText (), FIFTH , "double" ));
114
+ isType (estimates , t -> t .isNumeric () && isRepresentable (t ), sourceText (), SECOND , "numeric" )
115
+ )
116
+ .and (isType (trialCount , t -> t == DataType .INTEGER , sourceText (), THIRD , "integer" ))
117
+ .and (isType (bucketCount , t -> t == DataType .INTEGER , sourceText (), FOURTH , "integer" ))
118
+ .and (isType (confidenceLevel , t -> t == DataType .DOUBLE , sourceText (), FIFTH , "double" ));
112
119
}
113
120
114
121
@ Override
115
122
public boolean foldable () {
116
- return bestEstimate .foldable () && estimates .foldable () && trialCount .foldable () && bucketCount .foldable () && confidenceLevel .foldable ();
123
+ return bestEstimate .foldable ()
124
+ && estimates .foldable ()
125
+ && trialCount .foldable ()
126
+ && bucketCount .foldable ()
127
+ && confidenceLevel .foldable ();
117
128
}
118
129
119
130
@ Override
@@ -149,7 +160,14 @@ public EvalOperator.ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvalua
149
160
150
161
@ Override
151
162
public Expression replaceChildren (List <Expression > newChildren ) {
152
- return new ConfidenceInterval (source (), newChildren .get (0 ), newChildren .get (1 ), newChildren .get (2 ), newChildren .get (3 ), newChildren .get (4 ));
163
+ return new ConfidenceInterval (
164
+ source (),
165
+ newChildren .get (0 ),
166
+ newChildren .get (1 ),
167
+ newChildren .get (2 ),
168
+ newChildren .get (3 ),
169
+ newChildren .get (4 )
170
+ );
153
171
}
154
172
155
173
@ Override
@@ -173,13 +191,27 @@ public boolean equals(Object obj) {
173
191
return false ;
174
192
}
175
193
ConfidenceInterval other = (ConfidenceInterval ) obj ;
176
- return Objects .equals (other .bestEstimate , bestEstimate ) && Objects .equals (other .estimates , estimates ) && Objects .equals (other .trialCount , trialCount )
177
- && Objects .equals (other .bucketCount , bucketCount ) && Objects .equals (other .confidenceLevel , confidenceLevel );
194
+ return Objects .equals (other .bestEstimate , bestEstimate )
195
+ && Objects .equals (other .estimates , estimates )
196
+ && Objects .equals (other .trialCount , trialCount )
197
+ && Objects .equals (other .bucketCount , bucketCount )
198
+ && Objects .equals (other .confidenceLevel , confidenceLevel );
178
199
}
179
200
180
201
@ Evaluator (extraName = "Double" )
181
- static void process (DoubleBlock .Builder builder , @ Position int position , DoubleBlock bestEstimateBlock , DoubleBlock estimatesBlock , IntBlock trialCountBlock , IntBlock bucketCountBlock , DoubleBlock confidenceLevelBlock ) {
182
- if (bestEstimateBlock .getValueCount (position ) != 1 || trialCountBlock .getValueCount (position ) != 1 || bucketCountBlock .getValueCount (position ) != 1 || confidenceLevelBlock .getValueCount (position ) != 1 ) {
202
+ static void process (
203
+ DoubleBlock .Builder builder ,
204
+ @ Position int position ,
205
+ DoubleBlock bestEstimateBlock ,
206
+ DoubleBlock estimatesBlock ,
207
+ IntBlock trialCountBlock ,
208
+ IntBlock bucketCountBlock ,
209
+ DoubleBlock confidenceLevelBlock
210
+ ) {
211
+ if (bestEstimateBlock .getValueCount (position ) != 1
212
+ || trialCountBlock .getValueCount (position ) != 1
213
+ || bucketCountBlock .getValueCount (position ) != 1
214
+ || confidenceLevelBlock .getValueCount (position ) != 1 ) {
183
215
builder .appendNull ();
184
216
return ;
185
217
}
@@ -200,8 +232,19 @@ static void process(DoubleBlock.Builder builder, @Position int position, DoubleB
200
232
}
201
233
202
234
@ Evaluator (extraName = "Int" )
203
- static void process (IntBlock .Builder builder , @ Position int position , IntBlock bestEstimateBlock , IntBlock estimatesBlock , IntBlock trialCountBlock , IntBlock bucketCountBlock , DoubleBlock confidenceLevelBlock ) {
204
- if (bestEstimateBlock .getValueCount (position ) != 1 || trialCountBlock .getValueCount (position ) != 1 || bucketCountBlock .getValueCount (position ) != 1 || confidenceLevelBlock .getValueCount (position ) != 1 ) {
235
+ static void process (
236
+ IntBlock .Builder builder ,
237
+ @ Position int position ,
238
+ IntBlock bestEstimateBlock ,
239
+ IntBlock estimatesBlock ,
240
+ IntBlock trialCountBlock ,
241
+ IntBlock bucketCountBlock ,
242
+ DoubleBlock confidenceLevelBlock
243
+ ) {
244
+ if (bestEstimateBlock .getValueCount (position ) != 1
245
+ || trialCountBlock .getValueCount (position ) != 1
246
+ || bucketCountBlock .getValueCount (position ) != 1
247
+ || confidenceLevelBlock .getValueCount (position ) != 1 ) {
205
248
builder .appendNull ();
206
249
return ;
207
250
}
@@ -222,8 +265,19 @@ static void process(IntBlock.Builder builder, @Position int position, IntBlock b
222
265
}
223
266
224
267
@ Evaluator (extraName = "Long" )
225
- static void process (LongBlock .Builder builder , @ Position int position , LongBlock bestEstimateBlock , LongBlock estimatesBlock , IntBlock trialCountBlock , IntBlock bucketCountBlock , DoubleBlock confidenceLevelBlock ) {
226
- if (bestEstimateBlock .getValueCount (position ) != 1 || trialCountBlock .getValueCount (position ) != 1 || bucketCountBlock .getValueCount (position ) != 1 || confidenceLevelBlock .getValueCount (position ) != 1 ) {
268
+ static void process (
269
+ LongBlock .Builder builder ,
270
+ @ Position int position ,
271
+ LongBlock bestEstimateBlock ,
272
+ LongBlock estimatesBlock ,
273
+ IntBlock trialCountBlock ,
274
+ IntBlock bucketCountBlock ,
275
+ DoubleBlock confidenceLevelBlock
276
+ ) {
277
+ if (bestEstimateBlock .getValueCount (position ) != 1
278
+ || trialCountBlock .getValueCount (position ) != 1
279
+ || bucketCountBlock .getValueCount (position ) != 1
280
+ || confidenceLevelBlock .getValueCount (position ) != 1 ) {
227
281
builder .appendNull ();
228
282
return ;
229
283
}
@@ -243,7 +297,13 @@ static void process(LongBlock.Builder builder, @Position int position, LongBlock
243
297
builder .endPositionEntry ();
244
298
}
245
299
246
- public static double [] computeConfidenceInterval (double bestEstimate , double [] estimates , int trialCount , int bucketCount , double confidenceLevel ) {
300
+ public static double [] computeConfidenceInterval (
301
+ double bestEstimate ,
302
+ double [] estimates ,
303
+ int trialCount ,
304
+ int bucketCount ,
305
+ double confidenceLevel
306
+ ) {
247
307
System .out .println ("bestEstimate = " + bestEstimate + ", estimates = " + java .util .Arrays .toString (estimates ));
248
308
Mean means = new Mean ();
249
309
Mean stddevs = new Mean ();
@@ -261,7 +321,9 @@ public static double[] computeConfidenceInterval(double bestEstimate, double[] e
261
321
means .increment (mean .getResult ());
262
322
stddevs .increment (stdDev .getResult ());
263
323
skews .increment (skew .getResult ());
264
- System .out .println ("trial " + trial + ": mean = " + mean .getResult () + ", stddev = " + stdDev .getResult () + ", skew = " + skew .getResult ());
324
+ System .out .println (
325
+ "trial " + trial + ": mean = " + mean .getResult () + ", stddev = " + stdDev .getResult () + ", skew = " + skew .getResult ()
326
+ );
265
327
}
266
328
System .out .println ("total: mean = " + means .getResult () + ", stddev = " + stddevs .getResult () + ", skew = " + skews .getResult ());
267
329
double sm = stddevs .getResult ();
0 commit comments