Skip to content

Commit d7b9434

Browse files
committed
don't correct multiple stats
1 parent 3d6947d commit d7b9434

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/PropagateSampleFrequencyToAggs.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,24 @@
88
package org.elasticsearch.xpack.esql.optimizer.rules.logical;
99

1010
import org.elasticsearch.xpack.esql.core.expression.Expression;
11+
import org.elasticsearch.xpack.esql.core.util.Holder;
1112
import org.elasticsearch.xpack.esql.expression.function.aggregate.AggregateFunction;
13+
import org.elasticsearch.xpack.esql.plan.logical.Aggregate;
1214
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
1315
import org.elasticsearch.xpack.esql.plan.logical.RandomSample;
1416
import org.elasticsearch.xpack.esql.rule.Rule;
1517

16-
import java.util.concurrent.atomic.AtomicReference;
17-
1818
public class PropagateSampleFrequencyToAggs extends Rule<LogicalPlan, LogicalPlan> {
1919
@Override
2020
public LogicalPlan apply(LogicalPlan logicalPlan) {
21-
AtomicReference<Expression> sampleProbability = new AtomicReference<>(null);
21+
Holder<Expression> sampleProbability = new Holder<>(null);
2222
return logicalPlan.transformUp(plan -> {
2323
if (plan instanceof RandomSample randomSample) {
2424
sampleProbability.set(randomSample.probability());
2525
}
26-
if (sampleProbability.get() != null) {
26+
if (plan instanceof Aggregate && sampleProbability.get() != null) {
2727
plan = plan.transformExpressionsOnly(AggregateFunction.class, af -> af.correctForSampling(sampleProbability.get()));
28+
sampleProbability.set(null);
2829
}
2930
return plan;
3031
});

0 commit comments

Comments
 (0)