Repository navigation
[BugFix] Fix empty PPL query returning 500 NullPointerException instead of 400 (#5867) - #5868
Conversation
…ad of 400 (opensearch-project#5867) The PPL grammar's root rule (pplStatement? EOF) accepts input with no statement, so an empty, whitespace-only or comment-only query parsed successfully and AstStatementBuilder returned a null Statement. The anonymizer then dereferenced it, and the resulting NullPointerException surfaced as a 500. Reject a root with no statement in AstStatementBuilder with a SyntaxCheckException, which is already classified as a client error, so execute, explain and analyze all return 400 "Query is empty". Signed-off-by: Jialiang Liang <jiallian@amazon.com>
Decision LogRoot Cause: Approach: Override Alternatives Rejected:
Pitfalls: In the YAML REST runner, Things to Watch: The SQL grammar has the same |
PR Reviewer Guide 🔍(Review updated until commit d2ea329)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to d2ea329
Previous suggestionsSuggestions up to commit 45655bd
|
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project check has failed because the head coverage (63.87%) is below the target coverage (99.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #5868 +/- ##
============================================
+ Coverage 63.78% 63.87% +0.09%
- Complexity 9063 9091 +28
============================================
Files 962 962
Lines 40974 41033 +59
Branches 4653 4668 +15
============================================
+ Hits 26136 26211 +75
+ Misses 13962 13944 -18
- Partials 876 878 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
...
Can we double check if similar issue on the SQL side? |
dai-chen
left a comment
There was a problem hiding this comment.
The root cause is in grammar rule root : pplStatement? EOF, but we cannot simply remove the ??
Make pplStatement required in the grammar's root rule instead of rejecting a statement-less root in AstStatementBuilder. Empty, whitespace-only and comment-only queries now fail in the parser with the standard SyntaxCheckException, so they return 400 like every other syntax error, and the visitRoot override is no longer needed. Move the unit coverage to PPLSyntaxParserTest, drop the PPLServiceTest cases that duplicated the existing illegal-query handler tests, and update the IT and YAML expectations to the parser's message. testLineCommentShouldPass used Java text-block line continuations, which joined its third query into one line comment with no statement. It only passed because the root rule accepted an empty statement. Keep the newlines so it tests a statement surrounded by line comments. Signed-off-by: Jialiang Liang <jiallian@amazon.com>
|
Persistent review updated to latest commit d2ea329 |
|
@dai-chen just replying you in the separate thread since the previous review comment disappeared once i updated the commit:
This works - I have modified it to |
Yes - im thinking if we need to separate the sql fix into another PR - cause the symptom for sql is that it returns 400 but it exposed an NPE in its error msg. |
Description
An empty PPL query (
{"query": ""}), or one that is only whitespace or comments, returned a 500 withNullPointerException: ... because "plan" is null.Root cause: the grammar's
root : pplStatement? EOFrule accepts input with no statement, so parsing succeeds andAstStatementBuilderreturns anullStatement.PPLQueryDataAnonymizer.anonymizeStatement(null)then dereferences it. NPE isn't classified as a client error, so it maps to 500.Fix:
AstStatementBuilder.visitRootnow throwsSyntaxCheckException("Query is empty")when the root has nopplStatement.SyntaxCheckExceptionis already mapped to 400. Because the check sits at the parse-tree-to-statement boundary, it coversexecute,explainandanalyzeinPPLService, and the unified-APIPPLQueryParser. The grammar is unchanged.After the fix:
Related Issues
Resolves #5867
Check List
-s)spotlessCheckpassed