Fix fallback error handling to show original Calcite error#5133
Fix fallback error handling to show original Calcite error#5133Swiddis wants to merge 6 commits intoopensearch-project:mainfrom
Conversation
When Calcite falls back to V2 and V2 also fails, now correctly returns the original Calcite error instead of V2's generic "only supported when calcite enabled" message, improving error clarity for users. Fixes opensearch-project#5060. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughCentralized Calcite error handling in QueryService by adding propagateCalciteError(Throwable, ResponseListener); execute/explain paths for Calcite and legacy now delegate to it. Tests added to verify direct propagation and wrapping of Calcite errors when both Calcite and legacy analyses fail. Changes
Sequence Diagram(s)mermaid Client->>QueryService: request (execute/explain) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@core/src/main/java/org/opensearch/sql/executor/QueryService.java`:
- Around line 177-180: The current code always wraps calciteFailure.get() in a
RuntimeException; change this so we preserve the original Calcite exception
type: check calciteFailure.get() and if it's an instance of Exception call
listener.onFailure((Exception) calciteFailure.get()), otherwise wrap the
Throwable in a RuntimeException and call listener.onFailure(new
RuntimeException(calciteFailure.get())). Update the logic around calciteFailure
and listener.onFailure to perform this instanceof check and conditional
propagation.
🧹 Nitpick comments (1)
core/src/test/java/org/opensearch/sql/executor/QueryServiceTest.java (1)
94-114: Align test expectations with preserved Calcite exception types.If the production fix preserves the original Calcite exception, these assertions should expect the original type/message (not a
RuntimeExceptionwrapper).🔧 Suggested update
- assertTrue(e instanceof RuntimeException); - assertTrue(e.getCause() instanceof UnsupportedOperationException); - assertTrue(e.getCause().getMessage().contains("Calcite error")); + assertTrue(e instanceof UnsupportedOperationException); + assertTrue(e.getMessage().contains("Calcite error"));As per coding guidelines, use specific exception types with meaningful messages; ensure proper wrapping and propagation of Calcite vs V2 errors as appropriate to the PR.
core/src/main/java/org/opensearch/sql/executor/QueryService.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@core/src/main/java/org/opensearch/sql/executor/QueryService.java`:
- Around line 177-186: The current calciteFailure handling passes Exceptions
through but wraps Errors in CalciteUnsupportedException, which incorrectly wraps
ExceptionInInitializerError and loses the original Exception cause; update the
listener.onFailure logic in the calciteFailure handling (the block referencing
calciteFailure, listener.onFailure, and CalciteUnsupportedException) to: if t is
an Exception, pass it; else if t is an Error and t is an
ExceptionInInitializerError and t.getCause() is an Exception, pass t.getCause()
as the Exception; otherwise wrap in new
CalciteUnsupportedException(t.getMessage(), t). Apply the same change to the
other legacy handler block noted (the similar code around lines 215-224).
core/src/main/java/org/opensearch/sql/executor/QueryService.java
Outdated
Show resolved
Hide resolved
… calcite errors Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@core/src/main/java/org/opensearch/sql/executor/QueryService.java`:
- Around line 85-95: propagateCalciteExplainError currently wraps all Errors
(masking VirtualMachineError) and casts non-Exception Throwables unsafely;
change it to follow propagateCalciteError's pattern: if t is a
VirtualMachineError rethrow it, else if t is an Error wrap it in
CalciteUnsupportedException and call listener.onFailure(...), else if t is an
Exception call listener.onFailure((Exception) t), otherwise wrap the Throwable
in a RuntimeException (or similar unchecked wrapper) and pass that to
listener.onFailure to avoid ClassCastException; update the method
propagateCalciteExplainError accordingly.
- Around line 67-83: The propagateCalciteExplainError method currently wraps all
Errors (including VirtualMachineError) into CalciteUnsupportedException; change
it to mirror propagateCalciteError by detecting and re-throwing
VirtualMachineError and by unwrapping ExceptionInInitializerError when
appropriate. Specifically, in propagateCalciteExplainError first check if t is
an Exception and call listener.onFailure((Exception)t); then check for
ExceptionInInitializerError whose getException() is an Exception and call
listener.onFailure on that; then check if t is a VirtualMachineError and
re-throw it; finally, for other Errors (e.g., AssertError), call
listener.onFailure(new CalciteUnsupportedException(..., t)). Ensure the same
exception types and listener.onFailure usage as in propagateCalciteError are
used.
core/src/main/java/org/opensearch/sql/executor/QueryService.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@core/src/main/java/org/opensearch/sql/executor/QueryService.java`:
- Around line 67-82: Add unit tests for QueryService.propagateCalciteError to
cover the two missing branches: create a test that passes an
ExceptionInInitializerError which wraps an Exception and verify
ResponseListener.onFailure is invoked with the wrapped Exception (or its exact
type), and create a test that passes a subclass of VirtualMachineError (e.g.,
OutOfMemoryError) and assert that propagateCalciteError rethrows that error
instead of calling the listener; use a mocked ResponseListener to verify
interactions and place tests alongside other core tests under the same package
so they are committed with the new method.
Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
|
Could you add a The test should verify that when both Calcite and V2 fail, the error message correctly shows the Calcite error: Expected error:
|
Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
Description
When Calcite falls back to V2 and V2 also fails, now correctly returns the original Calcite error instead of V2's. A good example of when this matters is when using a
joinand theadcommand together:adforces a V2 fallback, thenjoinis only supported in V3, which gives an inconsistent error when V3 is already enabled:Related Issues
Resolves #5060
Check List
--signoffor-s.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.