【问题标题】:Unable to connect to HIVE2 via JAVA无法通过 JAVA 连接到 HIVE2
【发布时间】:2016-01-01 16:01:54
【问题描述】:

Referring to Hive2 创建了一个简单的java程序来连接到HIVE2服务器(不是本地的)在eclipse的类路径中的上述链接中添加了所有提到的jar但是当我运行它抛出的代码时错误为:

09:42:35,580  INFO Utils:285 - Supplied authorities: hdstg-c01-edge-03:20000
09:42:35,583  INFO Utils:372 - Resolved authority: hdstg-c01-edge-03:20000
09:42:35,656  INFO HiveConnection:189 - Will try to open client transport with JDBC Uri: jdbc:hive2://hdstg-c01-edge-03:20000
FAILED: f
java.lang.NoSuchMethodError: org.apache.thrift.protocol.TProtocol.getScheme()Ljava/lang/Class;
at org.apache.hive.service.cli.thrift.TCLIService$OpenSession_args.write(TCLIService.java:1854)
at org.apache.thrift.TServiceClient.sendBase(TServiceClient.java:63)
at org.apache.hive.service.cli.thrift.TCLIService$Client.send_OpenSession(TCLIService.java:150)
at org.apache.hive.service.cli.thrift.TCLIService$Client.OpenSession(TCLIService.java:142)
at org.apache.hive.jdbc.HiveConnection.openSession(HiveConnection.java:456)
at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:178)
at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:221)
at testScripts.HiveJdbcClient.f(HiveJdbcClient.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:648)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:834)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1142)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:771)
at org.testng.TestRunner.run(TestRunner.java:621)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
at org.testng.SuiteRunner.run(SuiteRunner.java:259)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1176)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1101)
at org.testng.TestNG.run(TestNG.java:1009)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

参考了herehere,但并没有解决问题。

【问题讨论】:

  • 你添加了所有的 jar 库,包括 thrift 吗?看起来你还没有添加 thrift jar 文件。
  • @MobinRanjbar:是的,它添加了更新的屏幕截图。
  • 尝试将您的 libthrift 版本降级到旧版本,例如 0.8.0 或 0.7.0。
  • @MobinRanjbar:以 0.8 运行,现在出现此错误:java.lang.NoClassDefFoundError: org/apache/thrift/scheme/StandardScheme
  • 在几次不成功运行后再次显示相同的旧错误。

标签: java hadoop jdbc hive hiveql


【解决方案1】:

您使用 hive2 类型的 jdbc url。

Hive wiki 中所述,不再推荐使用thrift jdbc:

JDBC

本文档描述了原始 Hive 服务器(有时称为 Thrift 服务器或 HiveServer1)的 JDBC 客户端。有关 HiveServer2 JDBC 客户端的信息,请参阅 HiveServer2 客户端文档中的 JDBC。推荐使用 HiveServer2;原始 HiveServer 存在多个并发问题,并且缺少 HiveServer2 中可用的一些功能。

在 hive2 jdbc 上结帐 this info。例如,驱动程序可以在这里找到:

http://mvnrepository.com/artifact/org.apache.hive/hive-jdbc/1.2.1

【讨论】:

  • 一一浏览了 JARS 并重建了项目,正如您所说的,这是由于 JAR 版本不兼容的问题,现在已解决,我可以连接到 hive,谢谢
  • @Jan 真的不推荐thrift jdbc吗?在同一个 wiki 上仅一页之遥,它说 HiveServer2“包括基于 Thrift 的 Hive 服务器”。 (cwiki.apache.org/confluence/display/Hive/HiveServer2+Overview)。我不知道我是否应该寻找节俭的罐子......
  • “不再推荐 JDBC”是什么意思?
猜你喜欢
  • 2017-03-07
  • 2018-02-04
  • 1970-01-01
  • 2020-03-02
  • 2021-09-14
  • 1970-01-01
  • 2012-11-21
  • 2015-07-25
  • 1970-01-01
相关资源
最近更新 更多