Skip to content

Commit 790ade4

Browse files
committed
spotless
1 parent e9f015b commit 790ade4

File tree

3 files changed

+134
-31
lines changed

3 files changed

+134
-31
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/approximate/Approximate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,8 @@ private LogicalPlan approximatePlan(double sampleProbability) {
635635
confidenceIntervalsAndReliable.add(
636636
new Alias(
637637
Source.EMPTY,
638-
"RELIABLE(" + output.name() + ")", new Reliable(Source.EMPTY, bucketsMv, trialCount, bucketCount)
638+
"RELIABLE(" + output.name() + ")",
639+
new Reliable(Source.EMPTY, bucketsMv, trialCount, bucketCount)
639640
)
640641
);
641642
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/approximate/ConfidenceInterval.java

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry;
3131
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
3232
import org.elasticsearch.xpack.esql.expression.function.Param;
33-
import org.elasticsearch.xpack.esql.expression.function.aggregate.StdDev;
3433
import org.elasticsearch.xpack.esql.expression.function.scalar.EsqlScalarFunction;
3534
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
3635
import 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();

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/approximate/Reliable.java

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ public class Reliable extends EsqlScalarFunction {
5656
private final Expression bucketCount;
5757

5858
@FunctionInfo(returnType = { "boolean", }, description = "...")
59-
public Reliable(Source source, @Param(name = "estimates", type = { "double", "int", "long" }) Expression estimates,
59+
public Reliable(
60+
Source source,
61+
@Param(name = "estimates", type = { "double", "int", "long" }) Expression estimates,
6062
@Param(name = "trialCount", type = { "int" }) Expression trialCount,
6163
@Param(name = "bucketCount", type = { "int" }) Expression bucketCount
6264
) {
@@ -67,7 +69,12 @@ public Reliable(Source source, @Param(name = "estimates", type = { "double", "in
6769
}
6870

6971
private Reliable(StreamInput in) throws IOException {
70-
this(Source.readFrom((PlanStreamInput) in), in.readNamedWriteable(Expression.class), in.readNamedWriteable(Expression.class), in.readNamedWriteable(Expression.class));
72+
this(
73+
Source.readFrom((PlanStreamInput) in),
74+
in.readNamedWriteable(Expression.class),
75+
in.readNamedWriteable(Expression.class),
76+
in.readNamedWriteable(Expression.class)
77+
);
7178
}
7279

7380
@Override
@@ -86,9 +93,8 @@ public String getWriteableName() {
8693
@Override
8794
protected TypeResolution resolveType() {
8895
return isType(estimates, t -> t.isNumeric() && isRepresentable(t), sourceText(), SECOND, "numeric").and(
89-
isType(trialCount, t -> t == DataType.INTEGER, sourceText(), THIRD, "integer")).and(
90-
isType(bucketCount, t -> t== DataType.INTEGER, sourceText(), FOURTH, "integer")
91-
);
96+
isType(trialCount, t -> t == DataType.INTEGER, sourceText(), THIRD, "integer")
97+
).and(isType(bucketCount, t -> t == DataType.INTEGER, sourceText(), FOURTH, "integer"));
9298
}
9399

94100
@Override
@@ -99,9 +105,24 @@ public boolean foldable() {
99105
@Override
100106
public EvalOperator.ExpressionEvaluator.Factory toEvaluator(ToEvaluator toEvaluator) {
101107
return switch (PlannerUtils.toElementType(estimates.dataType())) {
102-
case DOUBLE -> new ReliableDoubleEvaluator.Factory(source(), toEvaluator.apply(estimates), toEvaluator.apply(trialCount), toEvaluator.apply(bucketCount));
103-
case INT -> new ReliableIntEvaluator.Factory(source(), toEvaluator.apply(estimates), toEvaluator.apply(trialCount), toEvaluator.apply(bucketCount));
104-
case LONG -> new ReliableLongEvaluator.Factory(source(), toEvaluator.apply(estimates), toEvaluator.apply(trialCount), toEvaluator.apply(bucketCount));
108+
case DOUBLE -> new ReliableDoubleEvaluator.Factory(
109+
source(),
110+
toEvaluator.apply(estimates),
111+
toEvaluator.apply(trialCount),
112+
toEvaluator.apply(bucketCount)
113+
);
114+
case INT -> new ReliableIntEvaluator.Factory(
115+
source(),
116+
toEvaluator.apply(estimates),
117+
toEvaluator.apply(trialCount),
118+
toEvaluator.apply(bucketCount)
119+
);
120+
case LONG -> new ReliableLongEvaluator.Factory(
121+
source(),
122+
toEvaluator.apply(estimates),
123+
toEvaluator.apply(trialCount),
124+
toEvaluator.apply(bucketCount)
125+
);
105126
default -> throw EsqlIllegalArgumentException.illegalDataType(estimates.dataType());
106127
};
107128
}
@@ -132,12 +153,19 @@ public boolean equals(Object obj) {
132153
return false;
133154
}
134155
Reliable other = (Reliable) obj;
135-
return Objects.equals(other.estimates, estimates) && Objects.equals(other.trialCount, trialCount)
156+
return Objects.equals(other.estimates, estimates)
157+
&& Objects.equals(other.trialCount, trialCount)
136158
&& Objects.equals(other.bucketCount, bucketCount);
137159
}
138160

139161
@Evaluator(extraName = "Double")
140-
static void process(BooleanBlock.Builder builder, @Position int position, DoubleBlock estimatesBlock, IntBlock trialCountBlock, IntBlock bucketCountBlock) {
162+
static void process(
163+
BooleanBlock.Builder builder,
164+
@Position int position,
165+
DoubleBlock estimatesBlock,
166+
IntBlock trialCountBlock,
167+
IntBlock bucketCountBlock
168+
) {
141169
if (trialCountBlock.getValueCount(position) != 1 || bucketCountBlock.getValueCount(position) != 1) {
142170
builder.appendNull();
143171
return;
@@ -152,7 +180,13 @@ static void process(BooleanBlock.Builder builder, @Position int position, Double
152180
}
153181

154182
@Evaluator(extraName = "Int")
155-
static void process(BooleanBlock.Builder builder, @Position int position, IntBlock estimatesBlock, IntBlock trialCountBlock, IntBlock bucketCountBlock) {
183+
static void process(
184+
BooleanBlock.Builder builder,
185+
@Position int position,
186+
IntBlock estimatesBlock,
187+
IntBlock trialCountBlock,
188+
IntBlock bucketCountBlock
189+
) {
156190
if (trialCountBlock.getValueCount(position) != 1 || bucketCountBlock.getValueCount(position) != 1) {
157191
builder.appendNull();
158192
return;
@@ -167,7 +201,13 @@ static void process(BooleanBlock.Builder builder, @Position int position, IntBlo
167201
}
168202

169203
@Evaluator(extraName = "Long")
170-
static void process(BooleanBlock.Builder builder, @Position int position, LongBlock estimatesBlock, IntBlock trialCountBlock, IntBlock bucketCountBlock) {
204+
static void process(
205+
BooleanBlock.Builder builder,
206+
@Position int position,
207+
LongBlock estimatesBlock,
208+
IntBlock trialCountBlock,
209+
IntBlock bucketCountBlock
210+
) {
171211
if (trialCountBlock.getValueCount(position) != 1 || bucketCountBlock.getValueCount(position) != 1) {
172212
builder.appendNull();
173213
return;

0 commit comments

Comments
 (0)