|
27 | 27 | import org.elasticsearch.xpack.esql.core.expression.predicate.logical.Or; |
28 | 28 | import org.elasticsearch.xpack.esql.core.expression.predicate.operator.comparison.BinaryComparison; |
29 | 29 | import org.elasticsearch.xpack.esql.core.type.DataType; |
30 | | -import org.elasticsearch.xpack.esql.core.util.Holder; |
31 | 30 | import org.elasticsearch.xpack.esql.expression.function.UnsupportedAttribute; |
32 | 31 | import org.elasticsearch.xpack.esql.expression.function.aggregate.AggregateFunction; |
33 | 32 | import org.elasticsearch.xpack.esql.expression.function.aggregate.FilteredExpression; |
@@ -786,50 +785,23 @@ private static void checkFullTextSearchDisjunctions( |
786 | 785 | // Exit early if we already have a failures |
787 | 786 | return; |
788 | 787 | } |
789 | | - Expression left = or.left(); |
790 | | - boolean leftHasFullText = left.anyMatch(FullTextFunction.class::isInstance); |
791 | | - boolean leftHasOnlyFullText = onlyFullTextFunctionsInExpression(left); |
792 | | - Expression right = or.right(); |
793 | | - boolean rightHasFullText = right.anyMatch(FullTextFunction.class::isInstance); |
794 | | - boolean rightHasOnlyFullText = onlyFullTextFunctionsInExpression(right); |
795 | | - |
796 | | - if (leftHasFullText && leftHasOnlyFullText == false) { |
797 | | - disjunctionFailure(or, left, typeNameProvider, failures); |
798 | | - } else if (rightHasFullText && rightHasOnlyFullText == false) { |
799 | | - disjunctionFailure(or, right, typeNameProvider, failures); |
800 | | - } else if (leftHasFullText ^ rightHasFullText) { |
801 | | - disjunctionFailure(or, leftHasFullText ? left : right, typeNameProvider, failures); |
| 788 | + boolean hasFullText = or.anyMatch(FullTextFunction.class::isInstance); |
| 789 | + if (hasFullText) { |
| 790 | + boolean hasOnlyFullText = onlyFullTextFunctionsInExpression(or); |
| 791 | + if (hasOnlyFullText == false) { |
| 792 | + failures.add( |
| 793 | + fail( |
| 794 | + or, |
| 795 | + "Invalid condition [{}]. Full text functions can be used in an OR condition, " |
| 796 | + + "but only if just full text functions are used in the OR condition", |
| 797 | + or.sourceText() |
| 798 | + ) |
| 799 | + ); |
| 800 | + } |
802 | 801 | } |
803 | 802 | }); |
804 | 803 | } |
805 | 804 |
|
806 | | - /** |
807 | | - * Add a disjunction failure to the failures collection. |
808 | | - * @param parentExpression parent expression to include in the failure |
809 | | - * @param expressionWithError expression that provoked the failure |
810 | | - * @param typeNameProvider provider for the type name to add in the failure message |
811 | | - * @param failures failures collection to add to |
812 | | - */ |
813 | | - private static void disjunctionFailure( |
814 | | - Expression parentExpression, |
815 | | - Expression expressionWithError, |
816 | | - java.util.function.Function<FullTextFunction, String> typeNameProvider, |
817 | | - Set<Failure> failures |
818 | | - ) { |
819 | | - Holder<String> elementName = new Holder<>(); |
820 | | - // Get first function name to add to the failure message |
821 | | - expressionWithError.forEachDown(FullTextFunction.class, ftf -> elementName.set(typeNameProvider.apply(ftf))); |
822 | | - failures.add( |
823 | | - fail( |
824 | | - parentExpression, |
825 | | - "Invalid condition [{}]. {} can be used in an OR condition, " |
826 | | - + "but only if just full text functions are used in the OR condition", |
827 | | - parentExpression.sourceText(), |
828 | | - elementName.get() |
829 | | - ) |
830 | | - ); |
831 | | - } |
832 | | - |
833 | 805 | /** |
834 | 806 | * Checks whether an expression contains just full text functions or negations (NOT) and combinations (AND, OR) of full text functions |
835 | 807 | * |
|
0 commit comments