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
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();
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With