Skip to content

Commit 6051ec0

Browse files
committed
use samplebreaking in pushdown
1 parent 12df3c2 commit 6051ec0

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public LogicalPlan apply(LogicalPlan logicalPlan) {
4343
});
4444
}
4545

46-
private Expression getSampleProbability(List<Expression> sampleProbabilities, Source source) {
46+
private static Expression getSampleProbability(List<Expression> sampleProbabilities, Source source) {
4747
Expression result = null;
4848
for (Expression probability : sampleProbabilities) {
4949
result = result == null ? probability : new Mul(source, result, probability);

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

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,9 @@
1111
import org.elasticsearch.xpack.esql.core.expression.Foldables;
1212
import org.elasticsearch.xpack.esql.core.expression.Literal;
1313
import org.elasticsearch.xpack.esql.optimizer.LogicalOptimizerContext;
14-
import org.elasticsearch.xpack.esql.plan.logical.Enrich;
15-
import org.elasticsearch.xpack.esql.plan.logical.Eval;
16-
import org.elasticsearch.xpack.esql.plan.logical.Filter;
17-
import org.elasticsearch.xpack.esql.plan.logical.Insist;
1814
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
19-
import org.elasticsearch.xpack.esql.plan.logical.OrderBy;
20-
import org.elasticsearch.xpack.esql.plan.logical.Project;
21-
import org.elasticsearch.xpack.esql.plan.logical.RegexExtract;
2215
import org.elasticsearch.xpack.esql.plan.logical.Sample;
16+
import org.elasticsearch.xpack.esql.plan.logical.SampleBreaking;
2317
import org.elasticsearch.xpack.esql.plan.logical.UnaryPlan;
2418

2519
public class PushDownAndCombineSample extends OptimizerRules.ParameterizedOptimizerRule<Sample, LogicalOptimizerContext> {
@@ -32,20 +26,13 @@ public PushDownAndCombineSample() {
3226
protected LogicalPlan rule(Sample sample, LogicalOptimizerContext context) {
3327
LogicalPlan plan = sample;
3428
var child = sample.child();
35-
if (child instanceof Sample rsChild) {
36-
var probability = combinedProbability(context, sample, rsChild);
37-
var seed = combinedSeed(context, sample, rsChild);
38-
plan = new Sample(sample.source(), probability, seed, rsChild.child());
39-
} else if (child instanceof Enrich
40-
|| child instanceof Eval
41-
|| child instanceof Filter
42-
|| child instanceof Insist
43-
|| child instanceof OrderBy
44-
|| child instanceof Project
45-
|| child instanceof RegexExtract) {
46-
var unaryChild = (UnaryPlan) child;
47-
plan = unaryChild.replaceChild(sample.replaceChild(unaryChild.child()));
48-
}
29+
if (child instanceof Sample sampleChild) {
30+
var probability = combinedProbability(context, sample, sampleChild);
31+
var seed = combinedSeed(context, sample, sampleChild);
32+
plan = new Sample(sample.source(), probability, seed, sampleChild.child());
33+
} else if (child instanceof UnaryPlan unaryChild && child instanceof SampleBreaking == false) {
34+
plan = unaryChild.replaceChild(sample.replaceChild(unaryChild.child()));
35+
}
4936
return plan;
5037
}
5138

0 commit comments

Comments
 (0)