Hbase 1.0以後API改進與升級:java
最近發覺網上教程略顯陳舊,API仍是使用老式的API,致使代碼成片的deprecated警告。下面是升級後的HbaseAdmin Java API:spa
舊API | 新API |
Configuration config = new Configuration(); config.set("hbase.zookeeper.quorum", "a.com,b.com,c.com,d.com"); try (HBaseAdmin admin = new HBaseAdmin(config)) { // do something admin.close();//關閉鏈接 }catch (IOException e){ e.printStackTrace(); } |
Configuration config = new Configuration(); config.set("hbase.zookeeper.quorum", "a.com,b.com,c.com,d.com"); try(Connection connection = ConnectionFactory.createConnection(config)){// HBase 0.99+ HBaseAdmin admin = (HBaseAdmin) connection.getAdmin(); // do something admin.close();//關閉鏈接 }catch(IOException e){ e.printStackTrace(); } |
升級後跟後代的兼容性也會好不少。code
另外一個升級是Put類的升級,將add方法變爲addColumn方法:blog
舊API | 新API |
Put put = new Put(rowkey.getBytes()); put.add("cf1".getBytes(),"phone".getBytes(), phone.getBytes()); put.add("cf1".getBytes(),"dest".getBytes(), getPhone("151"+j).getBytes()); put.add("cf1".getBytes(),"type".getBytes(), (r.nextInt(2)+"").getBytes()); put.add("cf1".getBytes(),"date".getBytes(), date.getBytes());
|
Put put = new Put(rowkey.getBytes()); put.addColumn("cf1".getBytes(), "phone".getBytes(),phone.getBytes()); put.addColumn("cf1".getBytes(), "dest".getBytes(),getPhone("152"+j).getBytes()); put.addColumn("cf1".getBytes(), "type".getBytes(),(r.nextInt(2)+"").getBytes()); put.addColumn("cf1".getBytes(), "date".getBytes(),date.getBytes()); |