diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/regex/Like.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/regex/Like.java index ebc7572edf3..e38ae903b50 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/regex/Like.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/regex/Like.java @@ -19,6 +19,11 @@ public class Like extends BinaryExpression { super(location, left, right); } + @Override + public LikePattern right() { + return (LikePattern) super.right(); + } + @Override public Object fold() { Pattern p = Pattern.compile(right().fold().toString()); diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/regex/LikePattern.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/regex/LikePattern.java index 3056b03e144..24dc560ed66 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/regex/LikePattern.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/regex/LikePattern.java @@ -71,7 +71,7 @@ public class LikePattern extends LeafExpression { @Override public boolean foldable() { - return true; + return false; } @Override diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/regex/RLike.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/regex/RLike.java index ce0571c89e9..75c1400cb2e 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/regex/RLike.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/regex/RLike.java @@ -20,6 +20,11 @@ public class RLike extends BinaryExpression { super(location, left, right); } + @Override + public Literal right() { + return (Literal) super.right(); + } + @Override public Object fold() { Pattern p = Pattern.compile(right().fold().toString()); diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/planner/QueryTranslator.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/planner/QueryTranslator.java index 5a59b775640..fb9d7bee09e 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/planner/QueryTranslator.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/planner/QueryTranslator.java @@ -441,7 +441,7 @@ abstract class QueryTranslator { } if (e instanceof Like) { - LikePattern p = (LikePattern) ((Like) e).right(); + LikePattern p = ((Like) e).right(); if (inexact) { q = new QueryStringQuery(e.location(), p.asLuceneWildcard(), target); } diff --git a/sql/server/src/test/java/org/elasticsearch/xpack/sql/optimizer/OptimizerTests.java b/sql/server/src/test/java/org/elasticsearch/xpack/sql/optimizer/OptimizerTests.java index 18af4cdd5d5..c2bdab3d2d8 100644 --- a/sql/server/src/test/java/org/elasticsearch/xpack/sql/optimizer/OptimizerTests.java +++ b/sql/server/src/test/java/org/elasticsearch/xpack/sql/optimizer/OptimizerTests.java @@ -26,9 +26,6 @@ import org.elasticsearch.xpack.sql.expression.predicate.LessThanOrEqual; import org.elasticsearch.xpack.sql.expression.predicate.Not; import org.elasticsearch.xpack.sql.expression.predicate.Or; import org.elasticsearch.xpack.sql.expression.predicate.Range; -import org.elasticsearch.xpack.sql.expression.regex.Like; -import org.elasticsearch.xpack.sql.expression.regex.LikePattern; -import org.elasticsearch.xpack.sql.expression.regex.RLike; import org.elasticsearch.xpack.sql.optimizer.Optimizer.BinaryComparisonSimplification; import org.elasticsearch.xpack.sql.optimizer.Optimizer.BooleanLiteralsOnTheRight; import org.elasticsearch.xpack.sql.optimizer.Optimizer.BooleanSimplification; @@ -239,13 +236,6 @@ public class OptimizerTests extends ESTestCase { assertEquals(Literal.TRUE, new ConstantFolding().rule(new Not(EMPTY, Literal.FALSE))); } - public void testConstantFoldingLikes() { - assertEquals(Literal.TRUE, - new ConstantFolding().rule(new Like(EMPTY, Literal.of(EMPTY, "test_emp"), new LikePattern(EMPTY, "test%", (char) 0)))); - assertEquals(Literal.TRUE, - new ConstantFolding().rule(new RLike(EMPTY, Literal.of(EMPTY, "test_emp"), Literal.of(EMPTY, "test.emp")))); - } - public void testBinaryComparisonSimplification() { assertEquals(Literal.TRUE, new BinaryComparisonSimplification().rule(new Equals(EMPTY, L(5), L(5)))); assertEquals(Literal.TRUE, new BinaryComparisonSimplification().rule(new GreaterThanOrEqual(EMPTY, L(5), L(5)))); diff --git a/sql/server/src/test/java/org/elasticsearch/xpack/sql/parser/LikeEscapingParsingTests.java b/sql/server/src/test/java/org/elasticsearch/xpack/sql/parser/LikeEscapingParsingTests.java index 9e173dd5429..3d17fdd4931 100644 --- a/sql/server/src/test/java/org/elasticsearch/xpack/sql/parser/LikeEscapingParsingTests.java +++ b/sql/server/src/test/java/org/elasticsearch/xpack/sql/parser/LikeEscapingParsingTests.java @@ -31,7 +31,7 @@ public class LikeEscapingParsingTests extends ESTestCase { Expression exp = parser.createExpression(String.format(Locale.ROOT, "exp LIKE %s", pattern)); assertThat(exp, instanceOf(Like.class)); Like l = (Like) exp; - return (LikePattern) l.right(); + return l.right(); } public void testNoEscaping() {