Quantcast
Channel: Hortonworks » All Replies
Viewing all articles
Browse latest Browse all 3435

Sandbox : Hive Hbase Integration Problem

$
0
0

Hi,
I am using a sandbox Virtual Machine and trying to migrate data into HIVE_ON_HBASE, ie., creating table on hive and inserting values into hbase using hbase api, therefore retrieving data from hive using following code :

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.commons.configuration.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;

public class HiveHbaseIntegration {
private static String driverName = “org.apache.hive.jdbc.HiveDriver”;

public static void main(String[] args) throws SQLException, IOException {
Connection con = null;
try {
Class.forName(driverName);
con = DriverManager.getConnection(“jdbc:hive2://192.168.135.133:10000/default”,”hive”,”hive”);
System.out.println(“connection is “+con);
Statement stmt = con.createStatement();
String tableName = “sample123″;
stmt.execute(“drop table if exists ” + tableName);
stmt.close();
String a=”create table ” + tableName + ” (eid string,ename string,esal string,deptid string) ” +
“STORED BY \’org.apache.hadoop.hive.hbase.HBaseStorageHandler\’ ” +
“WITH SERDEPROPERTIES(\’hbase.columns.mapping\’ = \':key,sample123:ename,sample123:esal,sample123:deptid\’) ” +
“TBLPROPERTIES(\’hbase.table.name\’ = \’sample123\’)”;

stmt = con.createStatement();
stmt.execute(a);
stmt.close();
System.out.println(“table created “);
org.apache.hadoop.conf.Configuration conf = HBaseConfiguration.create();
conf.set(“hbase.defaults.for.version.skip”, “true”);
conf.set(“hbase.zookeeper.quorum”, “192.168.135.133”);

conf.addResource(conf);
HBaseAdmin.checkHBaseAvailable(conf);
System.out.println(“HBase is Available and is Running “);

System.out.println(“confuguration for hbase is”+conf);
HTable table = new HTable(conf, “sample123″);
Put p=new Put(Bytes.toBytes(“1″));
System.out.println(“row in table”+p);
p.add(Bytes.toBytes(“sample123″), Bytes.toBytes(“ename”),Bytes.toBytes(“solix”));
p.add(Bytes.toBytes(“sample123″), Bytes.toBytes(“esal”),Bytes.toBytes(“1000″));
p.add(Bytes.toBytes(“sample123″), Bytes.toBytes(“deptid”),Bytes.toBytes(“1000″));
System.out.println(“After populating Put “+p);

System.out.println(“row in table”+p);
Put p1=new Put(Bytes.toBytes(“2″));
p1.add(Bytes.toBytes(“sample123″), Bytes.toBytes(“ename”),Bytes.toBytes(“solix1″));
p1.add(Bytes.toBytes(“sample123″), Bytes.toBytes(“esal”),Bytes.toBytes(“10001″));
p1.add(Bytes.toBytes(“sample123″), Bytes.toBytes(“deptid”),Bytes.toBytes(“10001″));
Put p3=new Put(Bytes.toBytes(“3″));
p3.add(Bytes.toBytes(“sample123″), Bytes.toBytes(“ename”),Bytes.toBytes(“solix12″));
p3.add(Bytes.toBytes(“sample123″), Bytes.toBytes(“esal”),Bytes.toBytes(“100011″));
p3.add(Bytes.toBytes(“sample123″), Bytes.toBytes(“deptid”),Bytes.toBytes(“100011″));
table.put(p);
table.put(p1);
table.put(p3);
System.out.println(“After table Put “+p);
table.flushCommits();
System.out.println(“FLUSH COMMITS EXECUTED”);

} catch (Exception e) {
e.printStackTrace();
}finally {
// con.close();
}

}
}

Where i am getting the exception is

org.apache.hadoop.hbase.MasterNotRunningException: org.apache.hadoop.hbase.MasterNotRunningException: The node /hbase is not in ZooKeeper. It should have been written by the master. Check the value configured in ‘zookeeper.znode.parent’. There could be a mismatch with the one configured in the master.
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStub(ConnectionManager.java:1661)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.makeStub(ConnectionManager.java:1687)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.getKeepAliveMasterService(ConnectionManager.java:1904)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.isMasterRunning(ConnectionManager.java:932)
at org.apache.hadoop.hbase.client.HBaseAdmin.checkHBaseAvailable(HBaseAdmin.java:2409)
at connections.HiveHbaseIntegration.main(HiveHbaseIntegration.java:47)
Caused by: org.apache.hadoop.hbase.MasterNotRunningException: The node /hbase is not in ZooKeeper. It should have been written by the master. Check the value configured in ‘zookeeper.znode.parent’. There could be a mismatch with the one configured in the master.
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.checkIfBaseNodeAvailable(ConnectionManager.java:912)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.access$600(ConnectionManager.java:587)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStubNoRetries(ConnectionManager.java:1586)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStub(ConnectionManager.java:1633)
… 5 more

please help me to overcome the issue.


Viewing all articles
Browse latest Browse all 3435

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>