您的位置:首页 > 其它

Hbase实战笔记0001--Hbase基础02

2013-12-02 19:19 183 查看
1. 创建表
>create ‘users’,’info’
2. 查看表
>list
或>describe ‘users’
3. 建立连接
HTableInterface usersTable = newHTable(“users”);

Configuration myConf =HBaseConfiguration.create();
HTableInterface usersTable = newHTable(myconf,”users”);
myConf.set(“parameter_name”,”parameter_value”);
例如:
Myconf.set(“hbase.zookeeper.quorum”,”serverip”);
4. 连接管理(连接池)
HTablePool pool = new HTablePool();
HTableInterface usersTable =pool.getTable(“users”);
…//work with the table
usersTable.close();
5. 数据操作
5个hbase基本命令:Get, Put, Delete, Scan, Increment
Put put =new Put(Bytes.toBytes(“TheRealMT”));
Put.add(Bytes.toBytes(“info”),Bytes.toBytes(“name”),Bytes.toBytes(“Mark Twain”));
Put.add(Bytes.toBytes(“info”),Bytes.toBytes(“email”),Bytes.toBytes(“Samuel@163.com”));
Put.add(Bytes.toBytes(“info”),Bytes.toBytes(“password”),Bytes.toBytes(“Langhorne”));
usersTable.put(put);
usersTable.close();
6.工作机制:HBase写路径
默认情况下,执行写入时会写到两个地方:预写式日志(write-ahead log,也称为HLog)和MemStore。
MemStore是内存里的写入缓冲区,Hbase中数据在永久写入硬盘之前在这里积累。
7.读数据
Get get =new Get(Bytes.toBytes(“TheRealMT”));
Result r =usersTable.get(get);

Get get =new Get(Bytes.toBytes(“TheRealMT”));
get.addColumn(Bytes.toBytes(“info”),Bytes.toBytes(“password”));
Result r =usersTable.get(get);

Get get =new Get(Bytes.toBytes(“TheRealMT”));
get.addFamily(Bytes.toBytes(“info”));
Result r =usersTable.get(get);
byte[] b =r.getValue(Bytes.toBytes(“info”),Bytes.toBytes(“email”));
Stringemail = Bytes.toString(b);
8. 工作机制:Hbase读路径。P27
9.删除数据
Delete d =new Delete(Bytes.toBytes(“TheRealMT”));
usersTable.delete(d);

Delete d =new Delete(Bytes.toBytes(“TheRealMT”));
d.deleteColumns(Bytes.toBytes(“info”),Bytes.toBytes(“email”));
userTable.delete(d);
注意:deleteColumns()方法从行中删除一个单元,deleteColumn()方法删除单元的内容。
10. 合并:HBase的后台工作P29
11. 有时间版本的记录
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: