Skip to content

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

Merged
merged 4 commits into from
Jan 30, 2020

Conversation

matriv
Copy link
Contributor

@matriv matriv commented Jan 28, 2020

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

@elasticmachine
Copy link
Collaborator

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
Copy link
Contributor

@astefan astefan left a 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"));
Copy link
Contributor

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.

Copy link
Contributor Author

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')

@matriv matriv requested a review from astefan January 29, 2020 11:04
Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@costin costin left a 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 -> {
Copy link
Member

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.

@matriv matriv merged commit 65ad269 into elastic:master Jan 30, 2020
@matriv matriv deleted the fix-47446 branch January 30, 2020 11:22
matriv added a commit that referenced this pull request Jan 30, 2020
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
matriv added a commit that referenced this pull request Jan 30, 2020
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
(cherry picked from commit 65ad269)
@matriv matriv removed the v7.5.3 label Jan 30, 2020
matriv added a commit that referenced this pull request Jan 30, 2020
…#51673)

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
(cherry picked from commit 65ad269)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQL: selecting a full-text function generates error
6 participants