Cloudera-Impala-JDBC-Example icon indicating copy to clipboard operation
Cloudera-Impala-JDBC-Example copied to clipboard

org.apache.thrift.transport.TTransportException: Cannot write to null outputStream

Open twmht opened this issue 8 years ago • 4 comments

hi,

hi, I use gradle to run my program.

// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'application'

mainClassName = "com.my.impala.fetcher.Fetcher"
// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    mavenCentral()
    maven {
        url "https://repository.cloudera.com/artifactory/cloudera-repos/"
    }
}

run {
     if (project.hasProperty("params")) {
         args params
         // args Eval.me(params)
     }
}

test {
        testLogging {
            events "passed", "skipped", "failed", "standardOut", "standardError"
    }
}


// In this section you declare the dependencies for your production and test code
dependencies {
    // The production code uses the SLF4J logging API at compile time
    compile 'org.slf4j:slf4j-api:1.7.7'
    compile 'org.apache.hadoop:hadoop-client:2.6.0-cdh5.4.4.1'
    compile 'org.json:json:20140107'
    compile 'org.apache.hive:hive-jdbc:1.1.0'
}

The sample code is below.

Connection con = null;
ResultSet rs = null;
try {
    Class.forName(JDBC_DRIVER_NAME);
    con = DriverManager.getConnection(CONNECTION_HOST);
    Statement stmt = con.createStatement();
    rs = stmt.executeQuery(sqlStatement);
} catch (SQLException e) {
    e.printStackTrace();
    System.exit(-1);
} catch (Exception e) {
    e.printStackTrace();
    System.exit(-1);
} finally {
    try {
        con.close();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    }
}

rs.next();

Where rs.next will throw the following exception

org.apache.thrift.transport.TTransportException: Cannot write to null outputStream
        at org.apache.thrift.transport.TIOStreamTransport.write(TIOStreamTransport.java:142)
        at org.apache.thrift.protocol.TBinaryProtocol.writeI32(TBinaryProtocol.java:178)
        at org.apache.thrift.protocol.TBinaryProtocol.writeMessageBegin(TBinaryProtocol.java:106)
        at org.apache.thrift.TServiceClient.sendBase(TServiceClient.java:62)
        at org.apache.hive.service.cli.thrift.TCLIService$Client.send_FetchResults(TCLIService.java:495)
        at org.apache.hive.service.cli.thrift.TCLIService$Client.FetchResults(TCLIService.java:487)
        at org.apache.hive.jdbc.HiveQueryResultSet.next(HiveQueryResultSet.java:360)
        at com.my.impala.fetcher.Fetcher.main(Fetcher.java:54)
Exception in thread "main" java.sql.SQLException: Error retrieving next row
        at org.apache.hive.jdbc.HiveQueryResultSet.next(HiveQueryResultSet.java:388)
        at com.my.impala.fetcher.Fetcher.main(Fetcher.java:54)
Caused by: org.apache.thrift.transport.TTransportException: Cannot write to null outputStream
        at org.apache.thrift.transport.TIOStreamTransport.write(TIOStreamTransport.java:142)
        at org.apache.thrift.protocol.TBinaryProtocol.writeI32(TBinaryProtocol.java:178)
        at org.apache.thrift.protocol.TBinaryProtocol.writeMessageBegin(TBinaryProtocol.java:106)
        at org.apache.thrift.TServiceClient.sendBase(TServiceClient.java:62)
        at org.apache.hive.service.cli.thrift.TCLIService$Client.send_FetchResults(TCLIService.java:495)
        at org.apache.hive.service.cli.thrift.TCLIService$Client.FetchResults(TCLIService.java:487)
        at org.apache.hive.jdbc.HiveQueryResultSet.next(HiveQueryResultSet.java:360)
        ... 1 more

However, I can run the example from this repo without the failure.

I can not understand why I get this exception.

Thank you!

twmht avatar Sep 24 '15 12:09 twmht

This thrift issue might be when using different version of impala jar then the actual needed

Barak-Kedem avatar Nov 21 '15 12:11 Barak-Kedem

I am not familiar with gradle; please try again with the new branch I just pushed for Impala 2.3 and CDH5.5. The new branch has explicit versions of thrift jars included in the new JDBC driver download

onefoursix avatar Feb 21 '16 06:02 onefoursix

I met the save problem ,have you solved it?

sevenFire avatar Jul 18 '18 07:07 sevenFire

who solved it ? I met agin .

a871031791 avatar Aug 12 '18 04:08 a871031791