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. #116

Merged

Conversation

Yury-Fridlyand
Copy link

Co-authored-by: MaxKsyunz maxk@bitquilltech.com
Co-authored-by: forestmvey forestv@bitquilltech.com
Signed-off-by: Yury-Fridlyand yuryf@bitquilltech.com

Description

Re-creation of PR #108.

Issues Resolved

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.
A bit better error on typo in function name

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

before

TransportError(503, 'Exception', {'error': {'reason': 'There was internal problem at backend', 'details': '[701f78b8-da61-4eb1-a00a-18f089f5644d] Request SQLQueryRequest(jsonContent={"query":"SELECT phrase, insert_time2 from phrase WHERE match_phrase2(phrase, \'brown fox\', slop = 0)"}, query=SELECT phrase, insert_time2 from phrase WHERE match_phrase2(phrase, \'brown fox\', slop = 0), path=/_plugins/_sql/, format=jdbc, params={format=jdbc}, sanitize=true) is not supported and falling back to old SQL engine', 'type': 'Exception'}, 'status': 503})

after

{'reason': 'Invalid SQL query', 'details': "unsupported method: match_phrase2\nQuery failed on both V1 and V2 SQL parser engines. V2 SQL parser error following: \nFailed to parse query due to offending symbol [(] at: 'SELECT phrase, insert_time2 from phrase WHERE match_phrase2(' <--- HERE... More details: Expecting tokens in {<EOF>, ';'}", 'type': 'SqlParseException'}

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.

Co-authored-by: MaxKsyunz <maxk@bitquilltech.com>
Co-authored-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
@codecov

This comment was marked as spam.

Set<String> visitedParms = new HashSet();
// Aggregate parameters by name, so getting a Map<Name:String, List>
arguments.stream().collect(Collectors.groupingBy(a -> a.getArgName().toLowerCase()))
.forEach((k, v) -> {

Choose a reason for hiding this comment

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

@Yury-Fridlyand asked https://github.com/Bit-Quill/opensearch-project-sql/pull/108/files#r966554640
Do we need to aggregate all duplicates into one exception? Currently, function throws on first found duplicated parameter.

Choose a reason for hiding this comment

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

What do we do other places...? I think we always throw on the first failure, but maybe you have an example where we aggregate?

Copy link
Author

Choose a reason for hiding this comment

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

I can't find any examples. I don't think that we should worry about that, the probability that a user will specify multiple arguments more than once is extremely low I suppose. I just pointed that we have a room for further improvement.

private String details;

public String getDetails() {

Choose a reason for hiding this comment

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

why don't you use @getter too?

Copy link
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 8423187.

.put("lenient", (b, v) -> b.lenient(Boolean.parseBoolean(v.stringValue())))
.put("operator", (b, v) -> b.operator(Operator.fromString(v.stringValue())))
.put("auto_generate_synonyms_phrase_query", (b, v) -> b.autoGenerateSynonymsPhraseQuery(
FunctionParameterRepository.convertBoolValue(v,"auto_generate_synonyms_phrase_query")))

Choose a reason for hiding this comment

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

Suggested change
FunctionParameterRepository.convertBoolValue(v,"auto_generate_synonyms_phrase_query")))
FunctionParameterRepository.convertBoolValue(v, "auto_generate_synonyms_phrase_query")))

.put("analyze_wildcard", (b, v) -> b.analyzeWildcard(
FunctionParameterRepository.convertBoolValue(v, "analyze_wildcard")))
.put("auto_generate_synonyms_phrase_query", (b, v) -> b.autoGenerateSynonymsPhraseQuery(
FunctionParameterRepository.convertBoolValue(v,"auto_generate_synonyms_phrase_query")))

Choose a reason for hiding this comment

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

Suggested change
FunctionParameterRepository.convertBoolValue(v,"auto_generate_synonyms_phrase_query")))
FunctionParameterRepository.convertBoolValue(v, "auto_generate_synonyms_phrase_query")))

Copy link
Author

Choose a reason for hiding this comment

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

If I add the space, line pass 100 symbols limit and I have to break it. I would like to avoid it, but if you insist...

Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
@forestmvey
Copy link

forestmvey commented Sep 14, 2022

The query
select Title, Body from stackexchange_beer where match(Title, 'Cicerone', blah=0);
returns a useful error message of

{
  "error": {
    "reason": "Invalid SQL query",
    "details": "Failed to parse query due to offending symbol [blah] at: 'select Title, Body from stackexchange_beer where match(Title, Cicerone, blah' <--- HERE... More details: Expecting tokens in {'ALLOW_LEADING_WILDCARD', 'ANALYZER', 'ANALYZE_WILDCARD', 'AUTO_GENERATE_SYNONYMS_PHRASE_QUERY', 'BOOST', 'CUTOFF_FREQUENCY', 'DEFAULT_FIELD', 'DEFAULT_OPERATOR', 'ESCAPE', 'ENABLE_POSITION_INCREMENTS', 'FIELDS', 'FLAGS', 'FUZZINESS', 'FUZZY_MAX_EXPANSIONS', 'FUZZY_PREFIX_LENGTH', 'FUZZY_REWRITE', 'FUZZY_TRANSPOSITIONS', 'LENIENT', 'LOW_FREQ_OPERATOR', 'MAX_DETERMINIZED_STATES', 'MAX_EXPANSIONS', 'MINIMUM_SHOULD_MATCH', 'OPERATOR', 'PHRASE_SLOP', 'PREFIX_LENGTH', 'QUOTE_ANALYZER', 'QUOTE_FIELD_SUFFIX', 'REWRITE', 'SLOP', 'TIE_BREAKER', 'TIME_ZONE', 'TYPE', 'ZERO_TERMS_QUERY'}\nQuery failed on both V1 and V2 SQL engines. V1 SQL engine error following: \nsyntax error, expect AGAINST, actual EOF",
    "type": "ParserException"
  },
  "status": 400
}

but the query

select Title, Body from stackexchange_beer where match_phrase(Title, 'Cicerone', blah=0);

returns

{
  "error": {
    "reason": "There was internal problem at backend",
    "details": "[match_phrase] requires query value",
    "type": "IllegalArgumentException"
  },
  "status": 500
}

EDIT: Seems we could not re-produce this on another machine

😕

@Yury-Fridlyand Yury-Fridlyand merged commit aaa4fda into integ-improve-error-reporting Sep 17, 2022
@Yury-Fridlyand Yury-Fridlyand deleted the dev-improve-error-reporting branch September 17, 2022 02:28
Yury-Fridlyand added a commit that referenced this pull request Sep 28, 2022
…#116)

Co-authored-by: MaxKsyunz <maxk@bitquilltech.com>
Co-authored-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
Yury-Fridlyand added a commit that referenced this pull request Oct 28, 2022
…#116)

Co-authored-by: MaxKsyunz <maxk@bitquilltech.com>
Co-authored-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
GabeFernandez310 pushed a commit that referenced this pull request Oct 28, 2022
…#116)

Co-authored-by: MaxKsyunz <maxk@bitquilltech.com>
Co-authored-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>

Solved Merge Conflicts
forestmvey added a commit that referenced this pull request Nov 1, 2022
…#116)

Co-authored-by: MaxKsyunz <maxk@bitquilltech.com>
Co-authored-by: forestmvey <forestv@bitquilltech.com>
Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants