Skip to content

Commit d23998d

Browse files
committed
OR doesn't need to check for pushable full text functions
1 parent 6b1fc89 commit d23998d

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/FullTextFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ private static void checkFullTextSearchDisjunctions(Expression condition, Failur
276276
* @param or disjunction to check
277277
* @return true if the disjunction is pushable, false otherwise
278278
*/
279-
public static boolean checkDisjunctionPushable(Or or) {
279+
private static boolean checkDisjunctionPushable(Or or) {
280280
boolean hasFullText = or.anyMatch(FullTextFunction.class::isInstance);
281281
return hasFullText == false || onlyFullTextFunctionsInExpression(or);
282282
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/logical/Or.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
import org.elasticsearch.xpack.esql.core.expression.predicate.Negatable;
1313
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1414
import org.elasticsearch.xpack.esql.core.tree.Source;
15-
import org.elasticsearch.xpack.esql.expression.function.fulltext.FullTextFunction;
1615
import org.elasticsearch.xpack.esql.expression.predicate.Predicates;
17-
import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates;
1816

1917
import java.io.IOException;
2018

@@ -59,9 +57,4 @@ protected Expression canonicalize() {
5957
// NB: this add a circular dependency between Predicates / Logical package
6058
return Predicates.combineOr(Predicates.splitOr(super.canonicalize()));
6159
}
62-
63-
@Override
64-
public boolean translatable(LucenePushdownPredicates pushdownPredicates) {
65-
return super.translatable(pushdownPredicates) && FullTextFunction.checkDisjunctionPushable(this);
66-
}
6760
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LocalPhysicalPlanOptimizerTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,24 @@ public void testMatchFunctionWithNonPushableDisjunction() {
16731673
assertThat(fieldExtract.child(), instanceOf(EsQueryExec.class));
16741674
}
16751675

1676+
public void testMatchFunctionWithPushableDisjunction() {
1677+
String query = """
1678+
from test
1679+
| where match(last_name, "Smith") or emp_no > 10""";
1680+
var plan = plannerOptimizer.plan(query);
1681+
1682+
var limit = as(plan, LimitExec.class);
1683+
var exchange = as(limit.child(), ExchangeExec.class);
1684+
var project = as(exchange.child(), ProjectExec.class);
1685+
var fieldExtract = as(project.child(), FieldExtractExec.class);
1686+
var esQuery = as(fieldExtract.child(), EsQueryExec.class);
1687+
var boolQuery = as(esQuery.query(), BoolQueryBuilder.class);
1688+
Source source = new Source(2, 37, "emp_no > 10");
1689+
BoolQueryBuilder expected = new BoolQueryBuilder().should(new MatchQueryBuilder("last_name", "Smith").lenient(true))
1690+
.should(wrapWithSingleQuery(query, QueryBuilders.rangeQuery("emp_no").gt(10), "emp_no", source));
1691+
assertThat(esQuery.query().toString(), equalTo(expected.toString()));
1692+
}
1693+
16761694
private QueryBuilder wrapWithSingleQuery(String query, QueryBuilder inner, String fieldName, Source source) {
16771695
return FilterTests.singleValueQuery(query, inner, fieldName, source);
16781696
}

0 commit comments

Comments
 (0)