Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Hive connection executeUpdate() always returning count as zero

Scenario

I am trying to connect to Hive table from my local laptop to remote development servers via zookeepers cluster and trying to update a table column value. Hadoop cluster and Hive tables are also remotely located on Dev environment. I m using hive-jdbc.jar version 2.1.0 and hadoop-common version 2.7.1

Issue

Facing issue where table records are updated but stmt.getUpdateCount() and stmt.executeUpdate is returning -1 and 0 respectively. Code: Is there anything missing?? or At Hive tables getUpdateCount() behaves differently? Appreciate any quick help..

Code:

private static String driverName = "org.apache.hive.jdbc.HiveDriver"; 
public static void main(String[] args) throws SQLException, 
ClassNotFoundException {   
Class.forName(driverName);
Connection con = 
DriverManager.getConnection("jdbc:hive2://XXXX:XXXX/tibco,
XXXX:XXXX/tibco,XXXX:XXXX/tibco;
serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2;
"hive.execution.engine=tez", "hive", "");
Statement stmt = con.createStatement();
con.setAutoCommit(true);
System.out.println("created");
ResultSet rs = stmt.executeQuery("select * from tibco.log_events_poc");
ResultSet db1=stmt.executeQuery("desc tibco.log_events_poc");
System.out.println("tibco.log_events_poc table -->"+db1);
int rowsupdated = stmt.executeUpdate("update tibco.log_events_poc set 
name='sample1'");            
System.out.println("Number of Rows updated"+stmt.getUpdateCount());
System.out.println("Number of Rows updated"+rowsupdated);
stmt.close();           
con.close();
  }
like image 483
paresh Bapna Avatar asked Dec 07 '25 05:12

paresh Bapna


1 Answers

You can check out the sources of version 2.1.0. The driver completely ignores any update counts and always returns 0:

@Override
public int executeUpdate(String sql) throws SQLException {
    execute(sql);
    return 0;
}

The relevant feature request is here: https://issues.apache.org/jira/browse/HIVE-12382

like image 97
Lukas Eder Avatar answered Dec 08 '25 18:12

Lukas Eder