sql icon indicating copy to clipboard operation
sql copied to clipboard

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

Open Yury-Fridlyand opened this issue 3 years ago • 3 comments

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

  • [x] New functionality includes testing.
    • [x] 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
  • [x] 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 avatar Sep 17 '22 02:09 Yury-Fridlyand

Codecov Report

Merging #839 (b5ad3c9) into 2.x (3ca6450) will decrease coverage by 2.68%. The diff coverage is 100.00%.

@@             Coverage Diff              @@
##                2.x     #839      +/-   ##
============================================
- Coverage     97.85%   95.16%   -2.69%     
- Complexity     2989     3100     +111     
============================================
  Files           281      304      +23     
  Lines          7357     8362    +1005     
  Branches        467      612     +145     
============================================
+ Hits           7199     7958     +759     
- Misses          157      350     +193     
- Partials          1       54      +53     
Flag Coverage Δ
query-workbench 62.76% <ø> (?)
sql-engine 97.93% <100.00%> (+0.08%) :arrow_up:

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

Impacted Files Coverage Δ
...arch/sql/expression/datetime/DateTimeFunction.java 100.00% <ø> (ø)
.../lucene/relevance/FunctionParameterRepository.java 100.00% <100.00%> (ø)
.../filter/lucene/relevance/MatchBoolPrefixQuery.java 100.00% <100.00%> (ø)
...ilter/lucene/relevance/MatchPhrasePrefixQuery.java 100.00% <100.00%> (ø)
...ript/filter/lucene/relevance/MatchPhraseQuery.java 100.00% <100.00%> (ø)
...age/script/filter/lucene/relevance/MatchQuery.java 100.00% <100.00%> (ø)
...cript/filter/lucene/relevance/MultiFieldQuery.java 100.00% <100.00%> (ø)
...cript/filter/lucene/relevance/MultiMatchQuery.java 100.00% <100.00%> (ø)
...ript/filter/lucene/relevance/QueryStringQuery.java 100.00% <100.00%> (ø)
...script/filter/lucene/relevance/RelevanceQuery.java 100.00% <100.00%> (ø)
... and 41 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov-commenter avatar Sep 17 '22 02:09 codecov-commenter

Rebased to resolve conflicts.

Yury-Fridlyand avatar Sep 28 '22 21:09 Yury-Fridlyand

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

Yury-Fridlyand avatar Oct 28 '22 00:10 Yury-Fridlyand

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

Updated in 827a0cf0.

Yury-Fridlyand avatar Oct 28 '22 19:10 Yury-Fridlyand

Rebased to resolve conflicts.

Yury-Fridlyand avatar Oct 28 '22 20:10 Yury-Fridlyand

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.