Skip to content
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

Rework on error reporting to make it more verbose and human-friendly. #839

Conversation

Yury-Fridlyand
Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand commented Sep 17, 2022

Rework on #691

Co-authored-by: MaxKsyunz [email protected]
Co-authored-by: forestmvey [email protected]
Signed-off-by: Yury-Fridlyand [email protected]

Description

1.
Added cast validation and user-friendly error messages

SELECT phrase, insert_time2 from phrase WHERE match_phrase(phrase, 'brown fox', slop = 0.5);

before

{'reason': 'Invalid SQL query', 'details': 'For input string: "0.5"', 'type': 'NumberFormatException'}

after

{'reason': 'There was internal problem at backend', 'details': "Invalid slop value: '0.5'. Accepts only integer values.", 'type': 'RuntimeException'}

2.
Cast validation and user-friendly errors for all enum types

select `key` from calcs where multi_match([str1], 'DVD', zero_terms_query=meow);

before

{'reason': 'Invalid SQL query', 'details': 'No enum constant org.opensearch.index.search.MatchQuery.ZeroTermsQuery.MEOW', 'type': 'IllegalArgumentException'}

after

{'reason': 'There was internal problem at backend', 'details': "Invalid zero_terms_query value: 'meow'. Available values are: NONE, ALL, NULL.", 'type': 'RuntimeException'}

3.
Extended error message when incorrect parameters specified

SELECT phrase, insert_time2 from phrase WHERE match(phrase, 'brown fox', slop = 0);

before

{'reason': 'Invalid SQL query', 'details': 'Parameter slop is invalid for match function', 'type': 'SemanticCheckException'}

after

{'reason': 'Invalid SQL query', 'details': 'Parameter slop is invalid for match function. Available parameters are: analyzer, auto_generate_synonyms_phrase_query, boost, fuzziness, fuzzy_rewrite, fuzzy_transpositions, lenient, minimum_should_match, max_expansions, operator, prefix_length, zero_terms_query', 'type': 'SemanticCheckException'}

4.
Error aggregation from V1 and V2 engines Reverted

Issues Resolved

#838

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@Yury-Fridlyand Yury-Fridlyand requested a review from a team as a code owner September 17, 2022 02:34
@codecov-commenter
Copy link

codecov-commenter commented Sep 17, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.95%. Comparing base (3fd53ca) to head (89b3e1a).
Report is 478 commits behind head on 2.x.

Additional details and impacted files
@@             Coverage Diff              @@
##                2.x     #839      +/-   ##
============================================
- Coverage     97.58%   94.95%   -2.63%     
- Complexity     3162     3190      +28     
============================================
  Files           305      316      +11     
  Lines          7902     8646     +744     
  Branches        515      637     +122     
============================================
+ Hits           7711     8210     +499     
- Misses          190      382     +192     
- Partials          1       54      +53     
Flag Coverage Δ
query-workbench 62.76% <ø> (?)
sql-engine 97.60% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

MaxKsyunz
MaxKsyunz previously approved these changes Sep 24, 2022
@@ -70,8 +70,12 @@ public void sqlDeleteSettingsTest() throws IOException {
"{\n"
+ " \"error\": {\n"
+ " \"reason\": \"Invalid SQL query\",\n"
+ " \"details\": \"DELETE clause is disabled by default and will be deprecated. Using "
+ "the plugins.sql.delete.enabled setting to enable it\",\n"
+ " \"details\": \""
Copy link
Collaborator

Choose a reason for hiding this comment

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

comparing old one, the message is more confuse for customer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -305,7 +305,7 @@ SQL query::
{
"error": {
"reason": "Invalid SQL query",
"details": "DELETE clause is disabled by default and will be deprecated. Using the plugins.sql.delete.enabled setting to enable it",
"details": "Failed to parse query due to offending symbol [DELETE] at: 'DELETE' <--- HERE... More details: Expecting tokens in {<EOF>, 'DESCRIBE', 'SELECT', 'SHOW', ';'}\nQuery failed on both V1 and V2 SQL engines. V1 SQL engine error following: \nDELETE clause is disabled by default and will be deprecated. Using the plugins.sql.delete.enabled setting to enable it",
Copy link
Collaborator

Choose a reason for hiding this comment

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

any reason we want to expose V1/V2 engine info for customer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is already exposed, see #830/#1111.
Any ideas how to do this better?
I placed V2 error first, because it is more relevant for most cases (except this one).

Copy link
Collaborator

Choose a reason for hiding this comment

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

as discussed, we may want to simplify error message exposed to customer and log this kind of detailed message for our developer use.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in de104bf.

acarbonetto
acarbonetto previously approved these changes Sep 28, 2022
@Yury-Fridlyand
Copy link
Collaborator Author

Rebased to resolve conflicts.

@@ -0,0 +1,209 @@
package org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance;
Copy link
Member

Choose a reason for hiding this comment

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

missing license header. any reason why there are a lot of relevance related changes in this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you, fixed in a0f9970.
I updated all relevance functions to use this FunctionParameterRepository to validate functions' arguments' values and generate user-friendly error messages.
I also updated base RelevanceQuery class to do better argument check.

Copy link
Collaborator

Choose a reason for hiding this comment

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

just wondering did Github action fail on missing license header?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't have such validation yet.

joshuali925
joshuali925 previously approved these changes Sep 29, 2022
@@ -305,7 +305,7 @@ SQL query::
{
"error": {
"reason": "Invalid SQL query",
"details": "DELETE clause is disabled by default and will be deprecated. Using the plugins.sql.delete.enabled setting to enable it",
"details": "Failed to parse query due to offending symbol [DELETE] at: 'DELETE' <--- HERE... More details: Expecting tokens in {<EOF>, 'DESCRIBE', 'SELECT', 'SHOW', ';'}",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the originl message is much clear

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Revered in b5ad3c9.

* Can be deleted once the
* legacy SQL engine is deprecated.
*/
public static void setError(String error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we have better way to pass error messsage around instead of using threadcontext? we should consider deprecated threadcontext instead of add more capability to it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This feature (aggregating error messages from V1 and V2) will be removed soon along with V1. I can create/use a thread-safe singleton Map instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Revered in b5ad3c9.

Comment on lines 47 to 66
var field = arguments.stream()
.filter(a -> a.getArgName().equalsIgnoreCase("field"))
.findFirst()
.orElse(null);
var fields = arguments.stream()
.filter(a -> a.getArgName().equalsIgnoreCase("fields"))
.findFirst()
.orElse(null);
if (fields == null && field == null) {
throw new SemanticCheckException("Both 'field' and 'fields' parameters are missing.");
}
if (fields != null && field != null) {
throw new SemanticCheckException("Both 'field' and 'fields' parameters are given.");
}

var query = arguments.stream()
.filter(a -> a.getArgName().equalsIgnoreCase("query"))
.findFirst()
.orElseThrow(() -> new SemanticCheckException("'query' parameter is missing"));
T queryBuilder = createQueryBuilder((field != null ? field : fields), query);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Code specific to single field functions belongs in SingleFieldQuery class, multi-field functions -- MultiFieldQuery.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you, fixed in 2f1e302.
Notes:

  1. we can't check whether field and fields present both
  2. query check could be moved to a separate method to the superclass, but the benefit is rather low

@Yury-Fridlyand
Copy link
Collaborator Author

What about to move all queryBuildActions from CTORS of all inheritors of ...FieldQuery to FunctionParameterRepository?

@Yury-Fridlyand
Copy link
Collaborator Author

What about to move all queryBuildActions from CTORS of all inheritors of ...FieldQuery to FunctionParameterRepository?

Updated in 827a0cf.

…#116)

Co-authored-by: MaxKsyunz <[email protected]>
Co-authored-by: forestmvey <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
@Yury-Fridlyand Yury-Fridlyand force-pushed the integ-improve-error-reporting branch from 827a0cf to 89b3e1a Compare October 28, 2022 20:10
@Yury-Fridlyand
Copy link
Collaborator Author

Rebased to resolve conflicts.

Copy link
Collaborator

@penghuo penghuo left a comment

Choose a reason for hiding this comment

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

Thanks for the change!

@Yury-Fridlyand Yury-Fridlyand merged commit 21373b9 into opensearch-project:2.x Nov 1, 2022
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.4 failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.4 2.4
# Navigate to the new working tree
cd .worktrees/backport-2.4
# Create a new branch
git switch --create backport/backport-839-to-2.4
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 21373b9380dea321063dc6a5532b84a2ebec32a4
# Push it to GitHub
git push --set-upstream origin backport/backport-839-to-2.4
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.4

Then, create a pull request where the base branch is 2.4 and the compare/head branch is backport/backport-839-to-2.4.

Yury-Fridlyand added a commit to Bit-Quill/opensearch-project-sql that referenced this pull request Nov 1, 2022
…e-error-reporting

Rework on error reporting to make it more verbose and human-friendly.

(cherry picked from commit 21373b9)
Signed-off-by: Yury-Fridlyand <[email protected]>
@Yury-Fridlyand Yury-Fridlyand deleted the integ-improve-error-reporting branch November 1, 2022 23:39
@Yury-Fridlyand Yury-Fridlyand mentioned this pull request Nov 1, 2022
6 tasks
dai-chen pushed a commit that referenced this pull request Nov 3, 2022
…1008)

Rework on error reporting to make it more verbose and human-friendly.

(cherry picked from commit 21373b9)
Signed-off-by: Yury-Fridlyand <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.4 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants