Skip to content

Commit f0d3b76

Browse files
committed
slightly better FTF check for EVAL s = score(...)
1 parent a15844d commit f0d3b76

File tree

1 file changed

+17
-11
lines changed
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext

1 file changed

+17
-11
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/FullTextFunction.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646
import org.elasticsearch.xpack.esql.querydsl.query.TranslationAwareExpressionQuery;
4747
import org.elasticsearch.xpack.esql.score.ExpressionScoreMapper;
4848

49+
import java.util.ArrayList;
4950
import java.util.List;
5051
import java.util.Locale;
5152
import java.util.Map;
5253
import java.util.Objects;
53-
import java.util.concurrent.atomic.AtomicInteger;
5454
import java.util.function.BiConsumer;
5555
import java.util.function.Predicate;
5656

@@ -230,18 +230,24 @@ private static void checkFullTextQueryFunctions(LogicalPlan plan, Failures failu
230230
} else if (plan instanceof Aggregate agg) {
231231
checkFullTextFunctionsInAggs(agg, failures);
232232
} 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) {
240241
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+
)
242248
);
243-
});
244-
}
249+
}
250+
});
245251
}
246252
}
247253

0 commit comments

Comments
 (0)