Home > other >  The Spark unable to write data to the hbase
The Spark unable to write data to the hbase

Time:09-21

Specific code is as follows, has been the spark code can run normally, hbase can normal connection, but in the spark foreachPartition connection hbase is no error, no success will be written to hbase, verified foreachPartition code in separate runtime: no problem!


HiveContext hv=new HiveContext (sc);
DataFrame data=https://bbs.csdn.net/topics/hv.sql (" select * from url_pending limit 10 ");
The data show (2);
Data. ToJavaRDD (.) foreachPartition (new VoidFunction () {
@ Override
Public void call (Iterator Rows) {
The Row Row;
The Configuration conf=conf=HBaseConfiguration. The create ();
Conf. Set (" hbase. Rootdir ", "hdfs://archive.cloudera.com: 9000/hbase");
Zookeeper. Znode. Conf. Set (" parent ", "/hbase");
The conf. Set (" hbase. Zookeeper. Quorum ", "GDLT10471");
HConnection connection;
Try {
The connection=HConnectionManager. The createConnection (conf);
HTableInterface table=connection. GetTable (" url_matched ");
Table. SetAutoFlush (true);
List List=new ArrayList (a);
Put the Put;
While (rows. HasNext ()) {
The row=rows. The next ();
Put=new put (Bytes. ToBytes (UUID. RandomUUID (), toString ()));
The String url=row. Get String (0);
Put the add (Bytes. ToBytes (" baseData "), Bytes. ToBytes (" url "), Bytes. ToBytes (url));
Put. The add (Bytes. ToBytes (" baseData "), Bytes. ToBytes (" phone "), Bytes. ToBytes (row. Get string (1)));
System. The out. Println (" URL: "+ row. Get string (0) +" phone: "+ row. Get string (1));
List. Add (put);
}
Table. The put (list);
Table. The close ();
} the catch (IOException e) {
//TODO Auto - generated the catch block,
e.printStackTrace();
}
}
});
  • Related