Fix Like/RLike signature

Original commit: elastic/x-pack-elasticsearch@8ac7c17b39
This commit is contained in:
Costin Leau 2018-01-17 07:42:06 +02:00
parent f53a19374b
commit a80e5b73c9
6 changed files with 13 additions and 13 deletions

View File

@ -19,6 +19,11 @@ public class Like extends BinaryExpression {
super(location, left, right); super(location, left, right);
} }
@Override
public LikePattern right() {
return (LikePattern) super.right();
}
@Override @Override
public Object fold() { public Object fold() {
Pattern p = Pattern.compile(right().fold().toString()); Pattern p = Pattern.compile(right().fold().toString());

View File

@ -71,7 +71,7 @@ public class LikePattern extends LeafExpression {
@Override @Override
public boolean foldable() { public boolean foldable() {
return true; return false;
} }
@Override @Override

View File

@ -20,6 +20,11 @@ public class RLike extends BinaryExpression {
super(location, left, right); super(location, left, right);
} }
@Override
public Literal right() {
return (Literal) super.right();
}
@Override @Override
public Object fold() { public Object fold() {
Pattern p = Pattern.compile(right().fold().toString()); Pattern p = Pattern.compile(right().fold().toString());

View File

@ -441,7 +441,7 @@ abstract class QueryTranslator {
} }
if (e instanceof Like) { if (e instanceof Like) {
LikePattern p = (LikePattern) ((Like) e).right(); LikePattern p = ((Like) e).right();
if (inexact) { if (inexact) {
q = new QueryStringQuery(e.location(), p.asLuceneWildcard(), target); q = new QueryStringQuery(e.location(), p.asLuceneWildcard(), target);
} }

View File

@ -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.Not;
import org.elasticsearch.xpack.sql.expression.predicate.Or; import org.elasticsearch.xpack.sql.expression.predicate.Or;
import org.elasticsearch.xpack.sql.expression.predicate.Range; 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.BinaryComparisonSimplification;
import org.elasticsearch.xpack.sql.optimizer.Optimizer.BooleanLiteralsOnTheRight; import org.elasticsearch.xpack.sql.optimizer.Optimizer.BooleanLiteralsOnTheRight;
import org.elasticsearch.xpack.sql.optimizer.Optimizer.BooleanSimplification; 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))); 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() { public void testBinaryComparisonSimplification() {
assertEquals(Literal.TRUE, new BinaryComparisonSimplification().rule(new Equals(EMPTY, L(5), L(5)))); 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)))); assertEquals(Literal.TRUE, new BinaryComparisonSimplification().rule(new GreaterThanOrEqual(EMPTY, L(5), L(5))));

View File

@ -31,7 +31,7 @@ public class LikeEscapingParsingTests extends ESTestCase {
Expression exp = parser.createExpression(String.format(Locale.ROOT, "exp LIKE %s", pattern)); Expression exp = parser.createExpression(String.format(Locale.ROOT, "exp LIKE %s", pattern));
assertThat(exp, instanceOf(Like.class)); assertThat(exp, instanceOf(Like.class));
Like l = (Like) exp; Like l = (Like) exp;
return (LikePattern) l.right(); return l.right();
} }
public void testNoEscaping() { public void testNoEscaping() {