3030import org .elasticsearch .xpack .esql .expression .function .EsqlFunctionRegistry ;
3131import org .elasticsearch .xpack .esql .expression .function .FunctionInfo ;
3232import org .elasticsearch .xpack .esql .expression .function .Param ;
33- import org .elasticsearch .xpack .esql .expression .function .aggregate .StdDev ;
3433import org .elasticsearch .xpack .esql .expression .function .scalar .EsqlScalarFunction ;
3534import org .elasticsearch .xpack .esql .io .stream .PlanStreamInput ;
3635import org .elasticsearch .xpack .esql .planner .PlannerUtils ;
@@ -84,7 +83,14 @@ public ConfidenceInterval(
8483 }
8584
8685 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+ );
8894 }
8995
9096 @ Override
@@ -105,15 +111,20 @@ public String getWriteableName() {
105111 @ Override
106112 protected TypeResolution resolveType () {
107113 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" ));
112119 }
113120
114121 @ Override
115122 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 ();
117128 }
118129
119130 @ Override
@@ -149,7 +160,14 @@ public EvalOperator.ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvalua
149160
150161 @ Override
151162 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+ );
153171 }
154172
155173 @ Override
@@ -173,13 +191,27 @@ public boolean equals(Object obj) {
173191 return false ;
174192 }
175193 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 );
178199 }
179200
180201 @ 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 ) {
183215 builder .appendNull ();
184216 return ;
185217 }
@@ -200,8 +232,19 @@ static void process(DoubleBlock.Builder builder, @Position int position, DoubleB
200232 }
201233
202234 @ 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 ) {
205248 builder .appendNull ();
206249 return ;
207250 }
@@ -222,8 +265,19 @@ static void process(IntBlock.Builder builder, @Position int position, IntBlock b
222265 }
223266
224267 @ 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 ) {
227281 builder .appendNull ();
228282 return ;
229283 }
@@ -243,7 +297,13 @@ static void process(LongBlock.Builder builder, @Position int position, LongBlock
243297 builder .endPositionEntry ();
244298 }
245299
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+ ) {
247307 System .out .println ("bestEstimate = " + bestEstimate + ", estimates = " + java .util .Arrays .toString (estimates ));
248308 Mean means = new Mean ();
249309 Mean stddevs = new Mean ();
@@ -261,7 +321,9 @@ public static double[] computeConfidenceInterval(double bestEstimate, double[] e
261321 means .increment (mean .getResult ());
262322 stddevs .increment (stdDev .getResult ());
263323 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+ );
265327 }
266328 System .out .println ("total: mean = " + means .getResult () + ", stddev = " + stddevs .getResult () + ", skew = " + skews .getResult ());
267329 double sm = stddevs .getResult ();
0 commit comments