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. 有时间版本的记录
>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. 有时间版本的记录
相关文章推荐
- Hbase实战笔记0001--Hbase基础01
- hbase学习笔记——hbase基础概念理解
- Android进阶笔记02:Android 网络请求库的比较及实战(二)
- 机器学习实战笔记(Python实现)-02-k近邻算法(kNN)
- C基础学习笔记02
- 【JavaEE】javaEE学习笔记之-----(网上商城)项目基础实战
- 机器学习实战笔记 - 机器学习基础
- JQuery学习笔记02-选择器把需要的东西揪出来(基础)
- Java基础知识强化之集合框架笔记02:集合的继承体系图解
- 前端基础笔记02
- Linux实战教学笔记04:Linux命令基础
- [cocos2d-x学习笔记][入门基础]Box-2d物理引擎的使用02制作一个简易的愤怒小鸟Demo
- CSS实战手册_阅读笔记02_样式表
- Spring Cloud微服务实战阅读笔记(一) 基础知识
- 第五天02 JAVA基础语法(认识对象)(学习笔记)
- 笔记之java基础-02
- 【学习笔记】3D图形核心基础精炼版-4:stage3D实战-环境搭建
- [知了堂学习笔记] java基础回顾_02
- Java基础复习笔记 对象状态、引用种类、垃圾回收形式02
- iOS学习笔记之-C语言基础02(关键字、标识符、注释、数据类型)