Skip to content

Commit c91cf7c

Browse files
committed
Refactor detection method for full text functions
1 parent c198d91 commit c91cf7c

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Verifier.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -780,14 +780,14 @@ private static void checkFullTextSearchDisjunctions(
780780
Set<Failure> failures
781781
) {
782782
condition.forEachUp(Or.class, or -> {
783-
boolean left = checkFullTextSearchInDisjunctions(or.left());
784-
boolean right = checkFullTextSearchInDisjunctions(or.right());
783+
boolean left = onlyFullTextFunctionsInExpression(or.left());
784+
boolean right = onlyFullTextFunctionsInExpression(or.right());
785785
if (left ^ right) {
786786
Holder<String> elementName = new Holder<>();
787787
if (left) {
788-
or.right().forEachDown(FullTextFunction.class, ftf -> elementName.set(typeNameProvider.apply(ftf)));
789-
} else {
790788
or.left().forEachDown(FullTextFunction.class, ftf -> elementName.set(typeNameProvider.apply(ftf)));
789+
} else {
790+
or.right().forEachDown(FullTextFunction.class, ftf -> elementName.set(typeNameProvider.apply(ftf)));
791791
}
792792
failures.add(
793793
fail(
@@ -805,22 +805,22 @@ private static void checkFullTextSearchDisjunctions(
805805
/**
806806
* Checks whether an expression contains just full text functions or negations (NOT) and combinations (AND, OR) of full text functions
807807
*
808-
* @param expression parent expression to add to the failure message
808+
* @param expression expression to check
809809
* @return true if all children are full text functions or negations of full text functions, false otherwise
810810
*/
811-
private static boolean checkFullTextSearchInDisjunctions(Expression expression) {
811+
private static boolean onlyFullTextFunctionsInExpression(Expression expression) {
812812
if (expression instanceof FullTextFunction) {
813-
return false;
813+
return true;
814814
} else if (expression instanceof Not || expression instanceof BinaryLogic) {
815815
for (Expression child : expression.children()) {
816-
if (checkFullTextSearchInDisjunctions(child)) {
817-
return true;
816+
if (onlyFullTextFunctionsInExpression(child) == false) {
817+
return false;
818818
}
819819
}
820-
return false;
820+
return true;
821821
}
822822

823-
return true;
823+
return false;
824824
}
825825

826826
/**

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,14 +1168,14 @@ public void testMatchInsideEval() throws Exception {
11681168
public void testMatchFilter() throws Exception {
11691169
assertEquals(
11701170
"1:19: Invalid condition [first_name:\"Anna\" or starts_with(first_name, \"Anne\")]. "
1171-
+ "[:] operator can be used as part of an OR condition, " +
1172-
"but only if other full text functions are used as part of the condition",
1171+
+ "[:] operator can be used as part of an OR condition, "
1172+
+ "but only if other full text functions are used as part of the condition",
11731173
error("from test | where first_name:\"Anna\" or starts_with(first_name, \"Anne\")")
11741174
);
11751175

11761176
assertEquals(
1177-
"1:51: Invalid condition [first_name:\"Anna\" OR new_salary > 100]. [:] operator can be used as part of an OR " +
1178-
"condition, but only if other full text functions are used as part of the condition",
1177+
"1:51: Invalid condition [first_name:\"Anna\" OR new_salary > 100]. [:] operator can be used as part of an OR "
1178+
+ "condition, but only if other full text functions are used as part of the condition",
11791179
error("from test | eval new_salary = salary + 10 | where first_name:\"Anna\" OR new_salary > 100")
11801180
);
11811181
}

0 commit comments

Comments
 (0)