|
10 | 10 | import org.elasticsearch.xpack.sql.expression.Expression; |
11 | 11 | import org.elasticsearch.xpack.sql.expression.Expressions; |
12 | 12 | import org.elasticsearch.xpack.sql.expression.FieldAttribute; |
| 13 | +import org.elasticsearch.xpack.sql.expression.Foldables; |
13 | 14 | import org.elasticsearch.xpack.sql.expression.Literal; |
14 | 15 | import org.elasticsearch.xpack.sql.expression.NamedExpression; |
15 | 16 | import org.elasticsearch.xpack.sql.expression.Order; |
|
82 | 83 | import static java.util.Collections.emptyMap; |
83 | 84 | import static java.util.Collections.singletonList; |
84 | 85 | import static org.elasticsearch.xpack.sql.tree.Location.EMPTY; |
| 86 | +import static org.hamcrest.Matchers.contains; |
85 | 87 |
|
86 | 88 | public class OptimizerTests extends ESTestCase { |
87 | 89 |
|
@@ -311,6 +313,16 @@ public void testConstantFoldingIn() { |
311 | 313 | assertEquals(true, result.value()); |
312 | 314 | } |
313 | 315 |
|
| 316 | + public void testConstantFoldingIn_LeftValueNotFoldable() { |
| 317 | + Project p = new Project(EMPTY, FROM(), Collections.singletonList( |
| 318 | + new In(EMPTY, getFieldAttribute(), |
| 319 | + Arrays.asList(ONE, TWO, ONE, THREE, new Sub(EMPTY, THREE, ONE), ONE, FOUR, new Abs(EMPTY, new Sub(EMPTY, TWO, FIVE)))))); |
| 320 | + p = (Project) new ConstantFolding().apply(p); |
| 321 | + assertEquals(1, p.projections().size()); |
| 322 | + In in = (In) p.projections().get(0); |
| 323 | + assertThat(Foldables.valuesOf(in.list(), DataType.INTEGER), contains(1 ,2 ,3 ,4)); |
| 324 | + } |
| 325 | + |
314 | 326 | public void testArithmeticFolding() { |
315 | 327 | assertEquals(10, foldOperator(new Add(EMPTY, L(7), THREE))); |
316 | 328 | assertEquals(4, foldOperator(new Sub(EMPTY, L(7), THREE))); |
|
0 commit comments