Skip to content

Commit bdbdc52

Browse files
committed
Fix merge, allow disjunctions for full text functions
1 parent 2fc193c commit bdbdc52

File tree

1 file changed

+13
-2
lines changed
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis

1 file changed

+13
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.xpack.esql.core.expression.TypeResolutions;
2222
import org.elasticsearch.xpack.esql.core.expression.function.Function;
2323
import org.elasticsearch.xpack.esql.core.expression.predicate.BinaryOperator;
24+
import org.elasticsearch.xpack.esql.core.expression.predicate.logical.And;
2425
import org.elasticsearch.xpack.esql.core.expression.predicate.logical.BinaryLogic;
2526
import org.elasticsearch.xpack.esql.core.expression.predicate.logical.Not;
2627
import org.elasticsearch.xpack.esql.core.expression.predicate.logical.Or;
@@ -225,7 +226,7 @@ private static void checkScoreManipulationBetweenMultipleFulltextExpressions(Log
225226
p.forEachDown(Filter.class, f -> {
226227
Expression condition = f.condition();
227228
// check on instance type of type MatchQueryPredicate or FullTextFunction
228-
if (condition instanceof MatchQueryPredicate || condition instanceof FullTextFunction) {
229+
if (condition instanceof FullTextFunction) {
229230
f.forEachDown(Eval.class, eval -> {
230231
List<Alias> fields = eval.fields();
231232
for (Alias alias : fields) {
@@ -236,7 +237,7 @@ private static void checkScoreManipulationBetweenMultipleFulltextExpressions(Log
236237
eval.forEachDown(Filter.class, f2 -> {
237238
Expression f2Condition = f2.condition();
238239
// check on instance type of type MatchQueryPredicate or FullTextFunction
239-
if (f2Condition instanceof MatchQueryPredicate || f2Condition instanceof FullTextFunction) {
240+
if (f2Condition instanceof FullTextFunction) {
240241
failures.add(fail(p, "`_score` manipulation between fulltext expressions"));
241242
}
242243
});
@@ -677,12 +678,22 @@ private static void checkNotPresentInDisjunctions(
677678
java.util.function.Function<FullTextFunction, String> typeNameProvider,
678679
Set<Failure> failures
679680
) {
681+
680682
condition.forEachUp(Or.class, or -> {
683+
// If it's all full text functions, it's ok
684+
if (or.anyMatch(exp -> isFullTextOrBoolean(exp) == false)) {
685+
return;
686+
}
687+
681688
checkNotPresentInDisjunctions(or.left(), or, typeNameProvider, failures);
682689
checkNotPresentInDisjunctions(or.right(), or, typeNameProvider, failures);
683690
});
684691
}
685692

693+
private static boolean isFullTextOrBoolean(Expression exp) {
694+
return exp instanceof FullTextFunction || exp instanceof And || exp instanceof Or || exp instanceof Not;
695+
}
696+
686697
/**
687698
* Checks whether a condition contains a disjunction with the specified typeToken. Adds to failure if it does.
688699
*

0 commit comments

Comments
 (0)