Software Journey
Software Journey
Monday, February 13, 2012
HBase Java Client to Scan and Display Table Content
I have experimented with HBase, wrote a small client program to scan and display the content of table. It works with hbase-0.90.5 with hadoop-0.20.205.0. I put code here for sharing.
static void scanHbaseTableContent (String tableName, String familyName, String qualifierName) throws IOException { Configuration conf = HBaseConfiguration.create(); conf.set("hbase.master", "lei.hadoop.local:60000"); conf.set("hbase.zookeeper.quorum", "home.lei.local"); conf.set("hbase.cluster.distributed", "true"); Scan s = new Scan(); HTable table = new HTable(conf, tableName); s.addColumn(Bytes.toBytes(familyName), Bytes.toBytes(qualifierName)); ResultScanner scanner = table.getScanner(s); try { for (Result rr = scanner.next(); rr != null; rr = scanner.next()) { for (KeyValue kv : rr.raw()) { System.out.println("Key: " + Bytes.toStringBinary ( kv.getKey(), 2, kv.getRowLength() ) + " Value: " + Bytes.toStringBinary( kv.getValue() ) ); } } } finally { scanner.close(); } }
Enjoy.
1 comment:
Unknown
September 24, 2013 at 2:02 AM
thanks
Reply
Delete
Replies
Reply
Add comment
Load more...
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
thanks
ReplyDelete