Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR jdbc.HiveConnection: Error opening session Hive

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.

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 ?

like image 270
dilshad Avatar asked Jun 19 '15 06:06

dilshad


2 Answers

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)

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

Please refer this for more information.

like image 59
Rajesh N Avatar answered Nov 09 '22 16:11

Rajesh N


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.

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

like image 33
Thejas Nair Avatar answered Nov 09 '22 16:11

Thejas Nair