52169 & 52172 7x backport (#52256)

* Extract common optimizer tests (#52169)

(cherry picked from commit e5ad72bc22e9ec0686ab582195f0032efcb880bf)

* Hook in the optimizer rules (#52172)

(cherry picked from commit 1f90d8cc56052fbf2af604e72f9f5ca73f5e75d5)
This commit is contained in:
Andrei Stefan 2020-02-12 11:20:03 +02:00 committed by GitHub
parent daab242c75
commit a3ebacfcf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1327 additions and 1217 deletions

View File

@ -6,10 +6,18 @@
package org.elasticsearch.xpack.eql.optimizer;
import org.elasticsearch.xpack.ql.optimizer.OptimizerRules.BooleanLiteralsOnTheRight;
import org.elasticsearch.xpack.ql.optimizer.OptimizerRules.BooleanSimplification;
import org.elasticsearch.xpack.ql.optimizer.OptimizerRules.CombineBinaryComparisons;
import org.elasticsearch.xpack.ql.optimizer.OptimizerRules.ConstantFolding;
import org.elasticsearch.xpack.ql.optimizer.OptimizerRules.PropagateEquals;
import org.elasticsearch.xpack.ql.optimizer.OptimizerRules.PruneFilters;
import org.elasticsearch.xpack.ql.optimizer.OptimizerRules.PruneLiteralsInOrderBy;
import org.elasticsearch.xpack.ql.optimizer.OptimizerRules.SetAsOptimized;
import org.elasticsearch.xpack.ql.plan.logical.LogicalPlan;
import org.elasticsearch.xpack.ql.rule.RuleExecutor;
import static java.util.Collections.emptyList;
import java.util.Arrays;
public class Optimizer extends RuleExecutor<LogicalPlan> {
@ -19,6 +27,22 @@ public class Optimizer extends RuleExecutor<LogicalPlan> {
@Override
protected Iterable<RuleExecutor<LogicalPlan>.Batch> batches() {
return emptyList();
Batch operators = new Batch("Operator Optimization",
new ConstantFolding(),
// boolean
new BooleanSimplification(),
new BooleanLiteralsOnTheRight(),
// needs to occur before BinaryComparison combinations
new PropagateEquals(),
new CombineBinaryComparisons(),
// prune/elimination
new PruneFilters(),
new PruneLiteralsInOrderBy()
);
Batch label = new Batch("Set as Optimized", Limiter.ONCE,
new SetAsOptimized());
return Arrays.asList(operators, label);
}
}

View File

@ -36,6 +36,10 @@ public final class TestUtils {
randomAlphaOfLength(10));
}
public static Literal of(Object value) {
return of(Source.EMPTY, value);
}
/**
* Utility method for creating 'in-line' Literals (out of values instead of expressions).
*/