Skip to content

Commit b34f32c

Browse files
committed
fixes
1 parent 66deb06 commit b34f32c

File tree

5 files changed

+33
-18
lines changed

5 files changed

+33
-18
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public interface LogicalPlanRunner {
229229

230230
public Approximate(LogicalPlan logicalPlan) {
231231
this.logicalPlan = logicalPlan;
232-
this.preservesRows = verifyPlan();
232+
this.preservesRows = verifyPlan(logicalPlan);
233233
}
234234

235235
/**
@@ -245,7 +245,7 @@ public void approximate(LogicalPlanRunner runner, ActionListener<Result> listene
245245
* @return whether the part of the query until the STATS command preserves all rows
246246
* @throws VerificationException if the plan is not suitable for approximation
247247
*/
248-
private boolean verifyPlan() throws VerificationException {
248+
public static boolean verifyPlan(LogicalPlan logicalPlan) throws VerificationException {
249249
if (logicalPlan.preOptimized() == false) {
250250
throw new IllegalStateException("Expected pre-optimized plan");
251251
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ public class ConfidenceInterval extends EsqlScalarFunction {
6868
@FunctionInfo(returnType = { "double", }, description = "...")
6969
public ConfidenceInterval(
7070
Source source,
71-
@Param(name = "bestEstimate", type = { "double", "int", "long" }) Expression bestEstimate,
72-
@Param(name = "estimates", type = { "double", "int", "long" }) Expression estimates,
73-
@Param(name = "trialCount", type = { "int" }) Expression trialCount,
74-
@Param(name = "bucketCount", type = { "int" }) Expression bucketCount,
71+
@Param(name = "bestEstimate", type = { "double", "integer", "long" }) Expression bestEstimate,
72+
@Param(name = "estimates", type = { "double", "integer", "long" }) Expression estimates,
73+
@Param(name = "trialCount", type = { "integer" }) Expression trialCount,
74+
@Param(name = "bucketCount", type = { "integer" }) Expression bucketCount,
7575
@Param(name = "confidenceLevel", type = { "double" }) Expression confidenceLevel
7676
) {
77-
super(source, List.of(bestEstimate, estimates));
77+
super(source, List.of(bestEstimate, estimates, trialCount, bucketCount, confidenceLevel));
7878
this.bestEstimate = bestEstimate;
7979
this.estimates = estimates;
8080
this.trialCount = trialCount;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ public class Reliable extends EsqlScalarFunction {
5858
@FunctionInfo(returnType = { "boolean", }, description = "...")
5959
public Reliable(
6060
Source source,
61-
@Param(name = "estimates", type = { "double", "int", "long" }) Expression estimates,
62-
@Param(name = "trialCount", type = { "int" }) Expression trialCount,
63-
@Param(name = "bucketCount", type = { "int" }) Expression bucketCount
61+
@Param(name = "estimates", type = { "double", "integer", "long" }) Expression estimates,
62+
@Param(name = "trialCount", type = { "integer" }) Expression trialCount,
63+
@Param(name = "bucketCount", type = { "integer" }) Expression bucketCount
6464
) {
65-
super(source, List.of(estimates));
65+
super(source, List.of(estimates, trialCount, bucketCount));
6666
this.estimates = estimates;
6767
this.trialCount = trialCount;
6868
this.bucketCount = bucketCount;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlSession.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ public void execute(EsqlQueryRequest request, EsqlExecutionInfo executionInfo, P
212212
plan = explain.query();
213213
parsedPlanString = plan.toString();
214214
}
215-
<<<<<<< HEAD
216215
analyzedPlan(
217216
plan,
218217
configuration,
@@ -229,7 +228,7 @@ public void onResponse(LogicalPlan analyzedPlan) {
229228
SubscribableListener.<LogicalPlan>newForked(l -> preOptimizedPlan(analyzedPlan, logicalPlanPreOptimizer, l))
230229
.<LogicalPlan>andThen((l, p) -> {
231230
if (request.approximate()) {
232-
new Approximate(p); // to verify whether the pre-optimized plan is suitable for approximation
231+
Approximate.verifyPlan(p);
233232
}
234233
l.onResponse(p);
235234
})
@@ -292,7 +291,17 @@ public void executeOptimizedPlan(
292291
// TODO: this could be snuck into the underlying listener
293292
EsqlCCSUtils.updateExecutionInfoAtEndOfPlanning(executionInfo);
294293
// execute any potential subplans
295-
executeSubPlans(optimizedPlan, configuration, foldContext, planRunner, executionInfo, request, logicalPlanOptimizer, physicalPlanOptimizer, listener);
294+
executeSubPlans(
295+
optimizedPlan,
296+
configuration,
297+
foldContext,
298+
planRunner,
299+
executionInfo,
300+
request,
301+
logicalPlanOptimizer,
302+
physicalPlanOptimizer,
303+
listener
304+
);
296305
}
297306
}
298307

@@ -329,7 +338,12 @@ private void executeSubPlans(
329338
);
330339
} else if (request.approximate()) {
331340
new Approximate(optimizedPlan).approximate(
332-
(p, l) -> runner.run(logicalPlanToPhysicalPlan(optimizedPlan(p, logicalPlanOptimizer), request, physicalPlanOptimizer), configuration, foldContext, l),
341+
(p, l) -> runner.run(
342+
logicalPlanToPhysicalPlan(optimizedPlan(p, logicalPlanOptimizer), request, physicalPlanOptimizer),
343+
configuration,
344+
foldContext,
345+
l
346+
),
333347
listener
334348
);
335349
} else {

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/approximate/ApproximateTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.xpack.esql.optimizer.LogicalPlanPreOptimizer;
3131
import org.elasticsearch.xpack.esql.optimizer.LogicalPreOptimizerContext;
3232
import org.elasticsearch.xpack.esql.parser.EsqlParser;
33+
import org.elasticsearch.xpack.esql.parser.QueryParams;
3334
import org.elasticsearch.xpack.esql.plan.logical.Eval;
3435
import org.elasticsearch.xpack.esql.plan.logical.Filter;
3536
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
@@ -161,8 +162,8 @@ public void testVerify_incompatibleProcessingCommand() {
161162

162163
public void testVerify_incompatibleAggregation() {
163164
assertError(
164-
"FROM test | SORT emp_no STATS MIN(emp_no) | LIMIT 100",
165-
equalTo("line 1:19: aggregation function [MIN] cannot be approximated")
165+
"FROM test | SORT emp_no | STATS MIN(emp_no) | LIMIT 100",
166+
equalTo("line 1:33: aggregation function [MIN] cannot be approximated")
166167
);
167168
assertError(
168169
"FROM test | STATS SUM(emp_no), VALUES(emp_no), TOP(emp_no, 2, \"ASC\"), COUNT()",
@@ -309,7 +310,7 @@ private void assertError(String esql, Matcher<String> matcher) {
309310
private Approximate createApproximate(String query) throws Exception {
310311
SetOnce<LogicalPlan> resultHolder = new SetOnce<>();
311312
SetOnce<Exception> exceptionHolder = new SetOnce<>();
312-
LogicalPlan plan = parser.createStatement(query, TEST_CFG);
313+
LogicalPlan plan = parser.createStatement(query, new QueryParams());
313314
plan = analyzer.analyze(plan);
314315
plan.setAnalyzed();
315316
preOptimizer.preOptimize(plan, ActionListener.wrap(resultHolder::set, exceptionHolder::set));

0 commit comments

Comments
 (0)