|
@@ -181,9 +181,12 @@ public class OptimizerTests extends ESTestCase {
|
|
|
}
|
|
|
|
|
|
private static FieldAttribute getFieldAttribute() {
|
|
|
- return new FieldAttribute(EMPTY, "a", new EsField("af", DataType.INTEGER, emptyMap(), true));
|
|
|
+ return getFieldAttribute("a");
|
|
|
}
|
|
|
|
|
|
+ private static FieldAttribute getFieldAttribute(String name) {
|
|
|
+ return new FieldAttribute(EMPTY, name, new EsField(name + "f", DataType.INTEGER, emptyMap(), true));
|
|
|
+ }
|
|
|
|
|
|
public void testPruneSubqueryAliases() {
|
|
|
ShowTables s = new ShowTables(EMPTY, null, null);
|
|
@@ -1145,6 +1148,23 @@ public class OptimizerTests extends ESTestCase {
|
|
|
assertEquals(or, exp);
|
|
|
}
|
|
|
|
|
|
+ // (a = 1 AND b = 3 AND c = 4) OR (a = 2 AND b = 3 AND c = 4) -> (b = 3 AND c = 4) AND (a = 1 OR a = 2)
|
|
|
+ public void testBooleanSimplificationCommonExpressionSubstraction() {
|
|
|
+ FieldAttribute fa = getFieldAttribute("a");
|
|
|
+ FieldAttribute fb = getFieldAttribute("b");
|
|
|
+ FieldAttribute fc = getFieldAttribute("c");
|
|
|
+
|
|
|
+ Expression a1 = new Equals(EMPTY, fa, ONE);
|
|
|
+ Expression a2 = new Equals(EMPTY, fa, TWO);
|
|
|
+ And common = new And(EMPTY, new Equals(EMPTY, fb, THREE), new Equals(EMPTY, fc, FOUR));
|
|
|
+ And left = new And(EMPTY, a1, common);
|
|
|
+ And right = new And(EMPTY, a2, common);
|
|
|
+ Or or = new Or(EMPTY, left, right);
|
|
|
+
|
|
|
+ Expression exp = new BooleanSimplification().rule(or);
|
|
|
+ assertEquals(new And(EMPTY, common, new Or(EMPTY, a1, a2)), exp);
|
|
|
+ }
|
|
|
+
|
|
|
// (0 < a <= 1) OR (0 < a < 2) -> 0 < a < 2
|
|
|
public void testRangesOverlappingNoLowerBoundary() {
|
|
|
FieldAttribute fa = getFieldAttribute();
|
|
@@ -1289,7 +1309,7 @@ public class OptimizerTests extends ESTestCase {
|
|
|
Order firstOrderBy = new Order(EMPTY, firstField, OrderDirection.ASC, Order.NullsPosition.LAST);
|
|
|
Order secondOrderBy = new Order(EMPTY, secondField, OrderDirection.ASC, Order.NullsPosition.LAST);
|
|
|
|
|
|
- OrderBy orderByPlan = new OrderBy(EMPTY,
|
|
|
+ OrderBy orderByPlan = new OrderBy(EMPTY,
|
|
|
new Aggregate(EMPTY, FROM(), Arrays.asList(secondField, firstField), Arrays.asList(secondAlias, firstAlias)),
|
|
|
Arrays.asList(firstOrderBy, secondOrderBy));
|
|
|
LogicalPlan result = new Optimizer.SortAggregateOnOrderBy().apply(orderByPlan);
|
|
@@ -1321,7 +1341,7 @@ public class OptimizerTests extends ESTestCase {
|
|
|
Order firstOrderBy = new Order(EMPTY, firstAlias, OrderDirection.ASC, Order.NullsPosition.LAST);
|
|
|
Order secondOrderBy = new Order(EMPTY, secondAlias, OrderDirection.ASC, Order.NullsPosition.LAST);
|
|
|
|
|
|
- OrderBy orderByPlan = new OrderBy(EMPTY,
|
|
|
+ OrderBy orderByPlan = new OrderBy(EMPTY,
|
|
|
new Aggregate(EMPTY, FROM(), Arrays.asList(secondAlias, firstAlias), Arrays.asList(secondAlias, firstAlias)),
|
|
|
Arrays.asList(firstOrderBy, secondOrderBy));
|
|
|
LogicalPlan result = new Optimizer.SortAggregateOnOrderBy().apply(orderByPlan);
|