java 错误 jdbc.HiveConnection:打开会话 Hive 时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30931599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 17:50:59  来源:igfitidea点击:

ERROR jdbc.HiveConnection: Error opening session Hive

javahadoopjdbchive

提问by dilshad

i try to run JBDC code for Hive2 get error. i have hive 1.2.0 version hadoop 1.2.1 version. but in command line hive and beeline works fine without any problem.but with jdbc getting error.

我尝试为 Hive2 运行 JBDC 代码得到错误。我有 hive 1.2.0 版本 hadoop 1.2.1 版本。但在命令行 hive 和 beeline 工作正常,没有任何问题。但是 jdbc 出现错误。

import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;

public class HiveJdbcClient {
  private static String driverName = "org.apache.hive.jdbc.HiveDriver";

  /**
   * @param args
   * @throws SQLException
   */
  public static void main(String[] args) throws SQLException {
//BasicConfigurator.configure();

  try {
      Class.forName(driverName);
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    //replace "hive" here with the name of the user the queries should run as
    Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default","", "");
    Statement stmt = con.createStatement();
    String tableName = "cdr";
   stmt.execute("drop table if exists " + tableName);
// show tables
    String sql = "show tables '" + tableName + "'";
    System.out.println("Running: " + sql);
    ResultSet res = stmt.executeQuery(sql);
    if (res.next()) {
      System.out.println(res.getString(1));
    }

  }
}

i Get this Error While Run Code.

运行代码时出现此错误。

15/06/19 12:08:53 INFO jdbc.HiveConnection: Will try to open client transport with JDBC Uri: jdbc:hive2://localhost:10000/default
15/06/19 12:08:53 ERROR jdbc.HiveConnection: Error opening session
org.apache.thrift.TApplicationException: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{use:database=default})
        at org.apache.thrift.TApplicationException.read(TApplicationException.java:111)
        at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:71)
        at org.apache.hive.service.cli.thrift.TCLIService$Client.recv_OpenSession(TCLIService.java:156)
        at org.apache.hive.service.cli.thrift.TCLIService$Client.OpenSession(TCLIService.java:143)
        at org.apache.hive.jdbc.HiveConnection.openSession(HiveConnection.java:578)
        at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:192)
        at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
        at java.sql.DriverManager.getConnection(DriverManager.java:571)
        at java.sql.DriverManager.getConnection(DriverManager.java:215)
        at HiveJdbcClient.main(HiveJdbcClient.java:24)
Exception in thread "main" java.sql.SQLException: Could not establish connection to jdbc:hive2://localhost:10000/default: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{use:database=default})
        at org.apache.hive.jdbc.HiveConnection.openSession(HiveConnection.java:589)
        at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:192)
        at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
        at java.sql.DriverManager.getConnection(DriverManager.java:571)
        at java.sql.DriverManager.getConnection(DriverManager.java:215)
        at HiveJdbcClient.main(HiveJdbcClient.java:24)
Caused by: org.apache.thrift.TApplicationException: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null, configuration:{use:database=default})

Any Solution ?

任何解决方案?

回答by Rajesh N

org.apache.thrift.TApplicationException: Required field 'client_protocol' is unset!Struct:TOpenSessionReq(client_protocol:null, configuration:{use:database=default}) at org.apache.thrift.TApplicationException.read(TApplicationException.java:111)

org.apache.thrift.TApplicationException:未设置必填字段“client_protocol”!结构:TOpenSessionReq(client_protocol:null, configuration:{use:database=default}) 在 org.apache.thrift.TApplicationException.read(TApplicationException.java:111)

This error mostly occurs if you have version mismatchbetween your hive and hive-jdbc. Please check if both the versions match.

如果您的 hive 和 hive-jdbc 之间的版本不匹配,则通常会发生此错误。请检查两个版本是否匹配。

Please refer thisfor more information.

请参阅此处了解更多信息。

回答by Thejas Nair

This happens when a new version of JDBC driver is used against older version of HiveServer2. Use a jdbc driver that is same version as server (preferred), or an version that is older than the server.

当针对旧版本的 HiveServer2 使用新版本的 JDBC 驱动程序时会发生这种情况。使用与服务器版本相同的 jdbc 驱动程序(首选),或比服务器旧的版本。

The issue is tracked in https://issues.apache.org/jira/browse/HIVE-6050

该问题在https://issues.apache.org/jira/browse/HIVE-6050 中进行了跟踪

回答by Balkrushna Patil

"client_protocol" field is available in hive 1.1 version. You need to add hive-service-1.1.0.jar in classpath.

“client_protocol”字段在 hive 1.1 版本中可用。您需要在类路径中添加 hive-service-1.1.0.jar。

I hope your problem would get solved.

我希望你的问题能得到解决。