Commit 5935c44
authored
[ZEPPELIN-6225] Refactor HiveStatement unwrapping for improved readability and robustness
### What is this PR for?
To address this issue, nested type casting logic has been extracted into a dedicated static method (`unwrapHiveStatement`).
Since the immediate wrapper (like `DelegatingStatement`) in the Statement chain doesn't reliably support standard `isWrapperFor` and `unwrap(Class<T> iface)` calls (often returning `false` or throwing `SQLException` as observed in its implementation), a `while` loop is used to iteratively unwrap the underlying `DelegatingStatement` layers.
To prevent potential infinite loops or excessive unwrapping attempts, a **`MAX_STATEMENT_UNWRAP_DEPTH`** constant has been introduced, limiting the maximum unwrapping depth. Error handling and logging have also been improved to provide clearer insights into the unwrapping process.
In `HiveStatement.class` :
```
public boolean isWrapperFor(Class<?> iface) throws SQLException {
return false;
}
public <T> T unwrap(Class<T> iface) throws SQLException {
throw new SQLException("Cannot unwrap to " + iface);
}
```
### What type of PR is it?
Refactoring
### Todos
* [x] - Replace nested casts and Improve readability
### What is the Jira issue?
* Open an issue on [Jira](https://issues.apache.org/jira/secure/RapidBoard.jspa?rapidView=632&projectKey=ZEPPELIN&view=detail&selectedIssue=ZEPPELIN-6225)
### How should this be tested?
* Strongly recommended: add automated unit tests for any new or changed behavior
* Outline any manual steps to test the PR here.
### Questions:
* Does the license files need to update? - No
* Is there breaking changes for older versions? - No
* Does this needs documentation? - No
Closes #4968 from hyunw9/fix/simplify-hive-statement-unwrapping.
Signed-off-by: Cheng Pan <chengpan@apache.org>1 parent 1fe6b04 commit 5935c44
1 file changed
Lines changed: 23 additions & 2 deletions
Lines changed: 23 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
62 | | - | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
123 | 144 | | |
124 | 145 | | |
125 | 146 | | |
| |||
0 commit comments