Skip to content

Commit edc7a1f

Browse files
committed
disallow chained stats
1 parent a1518d0 commit edc7a1f

File tree

1 file changed

+11
-6
lines changed
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/approximate

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private boolean verifyPlan() {
192192
Holder<Boolean> hasFilters = new Holder<>(false);
193193
logicalPlan.transformUp(plan -> {
194194
if (encounteredStats.get() == false) {
195-
if (plan instanceof Aggregate aggregate) {
195+
if (plan instanceof Aggregate) {
196196
encounteredStats.set(true);
197197
plan.transformExpressionsOnly(AggregateFunction.class, aggFn -> {
198198
if (SUPPORTED_SINGLE_VALUED_AGGS.contains(aggFn.getClass()) == false && SUPPORTED_MULTI_VALUED_AGGS.contains(aggFn.getClass()) == false) {
@@ -205,6 +205,12 @@ private boolean verifyPlan() {
205205
} else if (ROW_PRESERVING_COMMANDS.contains(plan.getClass()) == false) {
206206
hasFilters.set(true);
207207
}
208+
} else {
209+
if (plan instanceof Aggregate) {
210+
throw new VerificationException(
211+
List.of(Failure.fail(plan, "query with multiple chained [STATS] cannot be approximated"))
212+
);
213+
}
208214
}
209215
return plan;
210216
});
@@ -330,15 +336,13 @@ private LogicalPlan approximatePlan(double sampleProbability) {
330336
return logicalPlan;
331337
}
332338

333-
logger.info("### BEFORE APPROXIMATE:\n{}", logicalPlan);
334-
335339
logger.debug("generating approximate plan (p={})", sampleProbability);
336340
Holder<Boolean> encounteredStats = new Holder<>(false);
337341
Map<NameId, List<Alias>> variablesWithConfidenceInterval = new HashMap<>();
338342

339343
Alias bucketIdField = new Alias(
340344
Source.EMPTY,
341-
"$$bucket_id",
345+
"$bucket_id",
342346
new MvAppend(
343347
Source.EMPTY,
344348
Literal.integer(Source.EMPTY, -1),
@@ -475,9 +479,10 @@ private LogicalPlan approximatePlan(double sampleProbability) {
475479
keepAttributes
476480
);
477481

478-
logger.info("### AFTER APPROXIMATE:\n{}", approximatePlan);
479-
480482
approximatePlan.setPreOptimized();
483+
484+
logger.debug("approximate plan:\n{}", approximatePlan);
485+
481486
return approximatePlan;
482487
}
483488

0 commit comments

Comments
 (0)