|
46 | 46 | import org.elasticsearch.xpack.esql.querydsl.query.TranslationAwareExpressionQuery; |
47 | 47 | import org.elasticsearch.xpack.esql.score.ExpressionScoreMapper; |
48 | 48 |
|
| 49 | +import java.util.ArrayList; |
49 | 50 | import java.util.List; |
50 | 51 | import java.util.Locale; |
51 | 52 | import java.util.Map; |
52 | 53 | import java.util.Objects; |
53 | | -import java.util.concurrent.atomic.AtomicInteger; |
54 | 54 | import java.util.function.BiConsumer; |
55 | 55 | import java.util.function.Predicate; |
56 | 56 |
|
@@ -230,18 +230,24 @@ private static void checkFullTextQueryFunctions(LogicalPlan plan, Failures failu |
230 | 230 | } else if (plan instanceof Aggregate agg) { |
231 | 231 | checkFullTextFunctionsInAggs(agg, failures); |
232 | 232 | } else { |
233 | | - // TODO : improve this check, as this is not 100% accurate |
234 | | - AtomicInteger scoredFullTextFunctions = new AtomicInteger(); |
235 | | - plan.forEachExpression(ScoreFunction.class, scoreFunction -> { |
236 | | - plan.forEachExpression(FullTextFunction.class, ftf -> { scoredFullTextFunctions.getAndIncrement(); }); |
237 | | - }); |
238 | | - if (scoredFullTextFunctions.get() == 0) { |
239 | | - plan.forEachExpression(FullTextFunction.class, ftf -> { |
| 233 | + // TODO : improve this check, as this is not so nice :( |
| 234 | + List<FullTextFunction> scoredFTFs = new ArrayList<>(); |
| 235 | + plan.forEachExpression( |
| 236 | + ScoreFunction.class, |
| 237 | + scoreFunction -> { plan.forEachExpression(FullTextFunction.class, scoredFTFs::add); } |
| 238 | + ); |
| 239 | + plan.forEachExpression(FullTextFunction.class, ftf -> { |
| 240 | + if (scoredFTFs.remove(ftf) == false) { |
240 | 241 | failures.add( |
241 | | - fail(ftf, "[{}] {} is only supported in WHERE and STATS commands", ftf.functionName(), ftf.functionType()) |
| 242 | + fail( |
| 243 | + ftf, |
| 244 | + "[{}] {} is only supported in WHERE and STATS commands, or in EVAL within score(.) function", |
| 245 | + ftf.functionName(), |
| 246 | + ftf.functionType() |
| 247 | + ) |
242 | 248 | ); |
243 | | - }); |
244 | | - } |
| 249 | + } |
| 250 | + }); |
245 | 251 | } |
246 | 252 | } |
247 | 253 |
|
|
0 commit comments