Skip to content

Commit ec38f32

Browse files
hadoopkandyzhaohehuhu
authored andcommitted
[KYUUBI apache#5918] Kyuubi BeeLine should check the relocated TTransportException
# 🔍 Description ## Issue References 🔗 This pull request fixes apache#5918, when Kyuubi beeline executes incorrect SQL,it will exit with exception: ``` java.lang.NoClassDefFoundError: org/apache/thrift/transport/TTransportException ``` ## Describe Your Solution 🔧 1.Supply `org.apache.thrift:libthrift` to `kyuubi-beeline` module. 2.We should override BeeLine's handleSQLException method,makes it compatible As we discussed, only `org.apache.kyuubi.shaded.thrift.transport.TTransportException` will be received by `kyuubi-beeline`,so it‘s unnecessary to add libthrift dependency to `kyuubi-beeline`. ## Types of changes 🔖 - [x] Bugfix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Test Plan 🧪 #### Behavior Without This Pull Request ⚰️ #### Behavior With This Pull Request 🎉 #### Related Unit Tests --- # Checklists ## 📝 Author Self Checklist - [ ] My code follows the [style guidelines](https://kyuubi.readthedocs.io/en/master/contributing/code/style.html) of this project - [ ] I have performed a self-review - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html) ## 📝 Committer Pre-Merge Checklist - [x] Pull request title is okay. - [x] No license issues. - [x] Milestone correctly set? - [ ] Test coverage is ok - [x] Assignees are selected. - [x] Minimum number of approvals - [x] No changes are requested **Be nice. Be informative.** Closes apache#5919 from hadoopkandy/KYUUBI-5918. Closes apache#5918 ee96c44 [kandy01.wang] [KYUUBI apache#5918] [Bug] kyuubi beeline exit with exception : java.lang.NoClassDefFoundError: org/apache/thrift/transport/TTransportException Authored-by: kandy01.wang <kandy01.wang@vipshop.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
1 parent 7bced41 commit ec38f32

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/KyuubiBeeLine.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
import java.io.IOException;
2121
import java.io.InputStream;
2222
import java.sql.Driver;
23+
import java.sql.SQLException;
24+
import java.sql.SQLWarning;
2325
import java.util.*;
2426
import org.apache.commons.cli.CommandLine;
2527
import org.apache.commons.cli.Options;
2628
import org.apache.commons.cli.ParseException;
2729
import org.apache.hive.common.util.HiveStringUtils;
30+
import org.apache.kyuubi.shaded.thrift.transport.TTransportException;
2831
import org.apache.kyuubi.util.reflect.DynConstructors;
2932
import org.apache.kyuubi.util.reflect.DynFields;
3033
import org.apache.kyuubi.util.reflect.DynMethods;
@@ -299,4 +302,56 @@ int runInit() {
299302
boolean dispatch(String line) {
300303
return super.dispatch(isPythonMode() ? line : HiveStringUtils.removeComments(line));
301304
}
305+
306+
@Override
307+
void handleSQLException(SQLException e) {
308+
if (e instanceof SQLWarning && !(getOpts().getShowWarnings())) {
309+
return;
310+
}
311+
312+
if (e.getCause() instanceof TTransportException) {
313+
switch (((TTransportException) e.getCause()).getType()) {
314+
case TTransportException.ALREADY_OPEN:
315+
error(loc("hs2-connection-already-open"));
316+
break;
317+
case TTransportException.END_OF_FILE:
318+
error(loc("hs2-unexpected-end-of-file"));
319+
break;
320+
case TTransportException.NOT_OPEN:
321+
error(loc("hs2-could-not-open-connection"));
322+
break;
323+
case TTransportException.TIMED_OUT:
324+
error(loc("hs2-connection-timed-out"));
325+
break;
326+
case TTransportException.UNKNOWN:
327+
error(loc("hs2-unknown-connection-problem"));
328+
break;
329+
default:
330+
error(loc("hs2-unexpected-error"));
331+
}
332+
}
333+
334+
error(
335+
loc(
336+
e instanceof SQLWarning ? "Warning" : "Error",
337+
new Object[] {
338+
e.getMessage() == null ? "" : e.getMessage().trim(),
339+
e.getSQLState() == null ? "" : e.getSQLState().trim(),
340+
new Integer(e.getErrorCode())
341+
}));
342+
343+
if (getOpts().getVerbose()) {
344+
e.printStackTrace(getErrorStream());
345+
}
346+
347+
if (!getOpts().getShowNestedErrs()) {
348+
return;
349+
}
350+
351+
for (SQLException nested = e.getNextException();
352+
nested != null && nested != e;
353+
nested = nested.getNextException()) {
354+
handleSQLException(nested);
355+
}
356+
}
302357
}

0 commit comments

Comments
 (0)