Skip to content

Commit 318b06e

Browse files
committed
Fix tests
1 parent ed62f9f commit 318b06e

File tree

2 files changed

+42
-48
lines changed

2 files changed

+42
-48
lines changed

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
package org.elasticsearch.xpack.esql.analysis;
99

1010
import org.elasticsearch.Build;
11-
import org.elasticsearch.common.logging.LoggerMessageFormat;
1211
import org.elasticsearch.test.ESTestCase;
1312
import org.elasticsearch.xpack.esql.VerificationException;
1413
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
@@ -1190,21 +1189,6 @@ public void testMatchInsideEval() throws Exception {
11901189
);
11911190
}
11921191

1193-
public void testMatchFilter() throws Exception {
1194-
assertEquals(
1195-
"1:19: Invalid condition [first_name:\"Anna\" or starts_with(first_name, \"Anne\")]. "
1196-
+ "Full text functions can be used in an OR condition, "
1197-
+ "but only if just full text functions are used in the OR condition",
1198-
error("from test | where first_name:\"Anna\" or starts_with(first_name, \"Anne\")")
1199-
);
1200-
1201-
assertEquals(
1202-
"1:51: Invalid condition [first_name:\"Anna\" OR new_salary > 100]. Full text functions can be"
1203-
+ " used in an OR condition, but only if just full text functions are used in the OR condition",
1204-
error("from test | eval new_salary = salary + 10 | where first_name:\"Anna\" OR new_salary > 100")
1205-
);
1206-
}
1207-
12081192
public void testMatchFunctionNotAllowedAfterCommands() throws Exception {
12091193
assertEquals(
12101194
"1:24: [MATCH] function cannot be used after LIMIT",
@@ -1426,25 +1410,13 @@ public void testMatchOperatorWithDisjunctions() {
14261410
}
14271411

14281412
private void checkWithDisjunctions(String functionName, String functionInvocation, String functionType) {
1429-
String expression = functionInvocation + " or length(first_name) > 12";
1430-
checkdisjunctionError("1:19", expression, functionName, functionType);
1431-
expression = "(" + functionInvocation + " or first_name is not null) or (length(first_name) > 12 and match(last_name, \"Smith\"))";
1432-
checkdisjunctionError("1:19", expression, functionName, functionType);
1433-
expression = functionInvocation + " or (last_name is not null and first_name is null)";
1434-
checkdisjunctionError("1:19", expression, functionName, functionType);
1435-
}
1436-
1437-
private void checkdisjunctionError(String position, String expression, String functionName, String functionType) {
1438-
assertEquals(
1439-
LoggerMessageFormat.format(
1440-
null,
1441-
"{}: Invalid condition [{}]. Full text functions can be used in an OR condition, "
1442-
+ "but only if just full text functions are used in the OR condition",
1443-
position,
1444-
expression
1445-
),
1446-
error("from test | where " + expression)
1413+
query("from test | where " + functionInvocation + " or length(first_name) > 12");
1414+
query(
1415+
"from test | where ("
1416+
+ functionInvocation
1417+
+ " or first_name is not null) or (length(first_name) > 12 and match(last_name, \"Smith\"))"
14471418
);
1419+
query("from test | where " + functionInvocation + " or (last_name is not null and first_name is null)");
14481420
}
14491421

14501422
public void testFullTextFunctionsDisjunctions() {
@@ -1456,17 +1428,13 @@ public void testFullTextFunctionsDisjunctions() {
14561428

14571429
private void checkWithFullTextFunctionsDisjunctions(String functionName, String functionInvocation, String functionType) {
14581430

1459-
String expression = functionInvocation + " or length(first_name) > 10";
1460-
checkdisjunctionError("1:19", expression, functionName, functionType);
1461-
1462-
expression = "match(last_name, \"Anneke\") or (" + functionInvocation + " and length(first_name) > 10)";
1463-
checkdisjunctionError("1:19", expression, functionName, functionType);
1464-
1465-
expression = "("
1466-
+ functionInvocation
1467-
+ " and length(first_name) > 0) or (match(last_name, \"Anneke\") and length(first_name) > 10)";
1468-
checkdisjunctionError("1:19", expression, functionName, functionType);
1469-
1431+
query("from test | where " + functionInvocation + " or length(first_name) > 10");
1432+
query("from test | where match(last_name, \"Anneke\") or (" + functionInvocation + " and length(first_name) > 10)");
1433+
query(
1434+
"from test | where ("
1435+
+ functionInvocation
1436+
+ " and length(first_name) > 0) or (match(last_name, \"Anneke\") and length(first_name) > 10)"
1437+
);
14701438
query("from test | where " + functionInvocation + " or match(first_name, \"Anna\")");
14711439
query("from test | where " + functionInvocation + " or not match(first_name, \"Anna\")");
14721440
query("from test | where (" + functionInvocation + " or match(first_name, \"Anna\")) and length(first_name) > 10");

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@
3838
import org.elasticsearch.xpack.esql.core.expression.Expressions;
3939
import org.elasticsearch.xpack.esql.core.expression.Literal;
4040
import org.elasticsearch.xpack.esql.core.expression.ReferenceAttribute;
41+
import org.elasticsearch.xpack.esql.core.expression.predicate.logical.Or;
4142
import org.elasticsearch.xpack.esql.core.tree.Source;
4243
import org.elasticsearch.xpack.esql.core.type.DataType;
4344
import org.elasticsearch.xpack.esql.core.type.EsField;
4445
import org.elasticsearch.xpack.esql.core.util.Holder;
4546
import org.elasticsearch.xpack.esql.enrich.ResolvedEnrichPolicy;
4647
import org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry;
4748
import org.elasticsearch.xpack.esql.expression.function.fulltext.Match;
49+
import org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.GreaterThan;
4850
import org.elasticsearch.xpack.esql.index.EsIndex;
4951
import org.elasticsearch.xpack.esql.index.IndexResolution;
5052
import org.elasticsearch.xpack.esql.optimizer.rules.logical.ExtractAggregateCommonFilter;
@@ -1632,19 +1634,43 @@ public void testMatchWithFieldCasting() {
16321634
assertThat(queryBuilder.value(), is(123456));
16331635
}
16341636

1635-
public void testMatchFunctionWithNonPushableDisjunction() {
1637+
public void testMatchFunctionWithPushableConjunction() {
16361638
String query = """
16371639
from test
16381640
| where match(last_name, "Smith") and length(first_name) > 10
16391641
""";
16401642
var plan = plannerOptimizer.plan(query);
16411643

1644+
var limit = as(plan, LimitExec.class);
1645+
var exchange = as(limit.child(), ExchangeExec.class);
1646+
var project = as(exchange.child(), ProjectExec.class);
1647+
var fieldExtract = as(project.child(), FieldExtractExec.class);
1648+
var filterLimit = as(fieldExtract.child(), LimitExec.class);
1649+
var filter = as(filterLimit.child(), FilterExec.class);
1650+
assertThat(filter.condition(), instanceOf(GreaterThan.class));
1651+
var fieldFilterExtract = as(filter.child(), FieldExtractExec.class);
1652+
var esQuery = as(fieldFilterExtract.child(), EsQueryExec.class);
1653+
assertThat(esQuery.query(), instanceOf(MatchQueryBuilder.class));
1654+
}
1655+
1656+
public void testMatchFunctionWithNonPushableDisjunction() {
1657+
String query = """
1658+
from test
1659+
| where match(last_name, "Smith") or length(first_name) > 10
1660+
""";
1661+
var plan = plannerOptimizer.plan(query);
1662+
16421663
var limit = as(plan, LimitExec.class);
16431664
var exchange = as(limit.child(), ExchangeExec.class);
16441665
var project = as(exchange.child(), ProjectExec.class);
16451666
var field = as(project.child(), FieldExtractExec.class);
1646-
var esQuery = as(field.child(), EsQueryExec.class);
1647-
assertThat(as(esQuery.limit(), Literal.class).value(), is(1000));
1667+
var filterLimit = as(field.child(), LimitExec.class);
1668+
var filter = as(filterLimit.child(), FilterExec.class);
1669+
Or or = as(filter.condition(), Or.class);
1670+
assertThat(or.left(), instanceOf(Match.class));
1671+
assertThat(or.right(), instanceOf(GreaterThan.class));
1672+
var fieldExtract = as(filter.child(), FieldExtractExec.class);
1673+
assertThat(fieldExtract.child(), instanceOf(EsQueryExec.class));
16481674
}
16491675

16501676
private QueryBuilder wrapWithSingleQuery(String query, QueryBuilder inner, String fieldName, Source source) {

0 commit comments

Comments
 (0)