-
Notifications
You must be signed in to change notification settings - Fork 25.3k
SQL: Verify Full-Text Search functions not allowed in SELECT #51568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Pinging @elastic/es-search (:Search/SQL) |
Add a verification that full-text search functions are not allowed in the SELECT clause, so that a nice error message is returned to the user early instead of an "ugly" exception. Fixes: elastic#47446
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM in general, but the error message needs to be changed.
// Full-Text search function are not allowed in the SELECT clause | ||
plan.forEachUp(p -> p.forEachExpressionsUp(e -> { | ||
if (e instanceof FullTextPredicate) { | ||
localFailures.add(fail(e, "Cannot use a Full-Text search functions in the SELECT clause")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message I think has several issues: why the capital letters for Full-Text, and why the plural functions
?Also, if you look at our docs - https://www.elastic.co/guide/en/elasticsearch/reference/7.x/sql-functions-search.html - full-text search functions include SCORE()
as well, but Score is not an instanceof FullTextPredicate
so it wouldn't match this condition.
So, try to adjust the error message not to partially conflict with the documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx, Rephrased the error message.
I chose not to refer to the exact usage in the user's query because it can be a large string, given the params that would be often used, e.g.:
QUERY('Man*', 'default_field=last_name;lenient=true', 'fuzzy_rewrite=scoring_boolean')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. Thanks!
final Map<Attribute, Expression> collectRefs = new LinkedHashMap<>(); | ||
|
||
// Full-Text search function are not allowed in the SELECT clause | ||
plan.forEachUp(p -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Despite being a small snippet, can you please extract it into its own static method - it's easier to reason about its purpose before looking at its details?
Thanks.
Add a verification that full-text search functions `MATCH()` and `QUERY()` are not allowed in the SELECT clause, so that a nice error message is returned to the user early instead of an "ugly" exception. Fixes: #47446
Add a verification that full-text search functions are not
allowed in the SELECT clause, so that a nice error message is
returned to the user early instead of an "ugly" exception.
Fixes: #47446