HBase - 计数器 - 计数器的介绍以及使用 | 那伊抹微笑
2017-05-02 08:57
405 查看
博文作者:那伊抹微笑
csdn 博客地址:http://blog.csdn.net/u012185296
itdog8 地址链接 : http://www.itdog8.com/thread-215-1-1.html
博文标题:HBase - 计数器 - 计数器的介绍以及使用 | 那伊抹微笑
个性签名:世界上最遥远的距离不是天涯。也不是海角,而是我站在妳的面前,妳却感觉不到我的存在
技术方向:Flume+Kafka+Storm+Redis/Hbase+Hadoop+Hive+Mahout+Spark ... 云计算技术
转载声明:能够转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明,谢谢合作!
qq交流群:214293307
(期待与你一起学习,共同进步)
1 计数器
计数器能够方便、高速地进行计数操作。并且避免了加锁等保证了原子性的操作。
1.1 Java API 操作 HBase 计数器
public Result increment(final Increment increment)
public long incrementColumnValue(final byte [] row, final byte [] family,
final byte [] qualifier, final long amount)
public long incrementColumnValue(final byte [] row, final byte [] family,
final byte [] qualifier, final long amount, final Durability durability)
从这 3 个 HBase 提供的 计数器 API 来看,能够知道有 单列计数器 和 多列计数器
pv + 1 的 Java 示比例如以下 :
_hTable.incrementColumnValue(Bytes.toBytes("row-zhangsan-001"), Bytes.toBytes("info"), Bytes.toBytes("pv"), 1L);
1.2 Shell 操作 HBase 计数器
hbase(main):011:0> incr 'user', 'row-zhangsan-001', 'cf1:pv', 10
hbase(main):012:0> incr 'user', 'row-zhangsan-001', 'cf1:pv', -1
hbase(main):013:0> scan 'user'
ROW COLUMN+CELL
row-zhangsan-001 column=cf1:pv, timestamp=1438853474770, value=\x00\x00\x00\x00\x00\x00\x00\x09
hbase(main):014:0> get_counter 'user', 'row-zhangsan-001', 'cf1:pv', ''
COUNTER VALUE = 9
// 看以下提示,给的样例仅仅要3个參数,为什么我要打4个才可以用???
hbase(main):015:0> get_counter 'user', 'row-zhangsan-001', 'cf1:pv'
ERROR: wrong number of arguments (3 for 4)
Here is some help for this command:
Return a counter cell value at specified table/row/column coordinates.
A cell cell should be managed with atomic increment function oh HBase
and the data should be binary encoded. Example:
hbase> get_counter 'ns1:t1', 'r1', 'c1'
hbase> get_counter 't1', 'r1', 'c1'
The same commands also can be run on a table reference. Suppose you had a reference
t to table 't1', the corresponding command would be:
hbase> t.get_counter 'r1', 'c1'
hbase(main):055:0> get 'test_icv_tmp_1', 'row-zhangsan-001', 'cf1:pv'
COLUMN CELL
cf1:pv timestamp=1438853974733, value=\x00\x00\x00\x00\x00\x00\x00\x0A
1 row(s) in 0.0080 seconds
hbase(main):056:0>
1.3 单列计数器
_hTable.incrementColumnValue(Bytes.toBytes("row-zhangsan-001"), Bytes.toBytes("info"), Bytes.toBytes("pv"), 10L); // pv +10
_hTable.incrementColumnValue(Bytes.toBytes("row-zhangsan-001"), Bytes.toBytes("info"), Bytes.toBytes("pv"), -1L); // pv -1
1.4 多列计数器
pv +2 的同一时候,uv 同一时候 +1
Increment increment = new Increment(Bytes.toBytes("row"));
increment.addColumn(Bytes.toBytes("info"), Bytes.toBytes("pv"), 1L); // pv +2
increment.addColumn(Bytes.toBytes("info"), Bytes.toBytes("uv"), 1L); // uv +1
_hTable.increment(increment);
csdn 博客地址:http://blog.csdn.net/u012185296
itdog8 地址链接 : http://www.itdog8.com/thread-215-1-1.html
博文标题:HBase - 计数器 - 计数器的介绍以及使用 | 那伊抹微笑
个性签名:世界上最遥远的距离不是天涯。也不是海角,而是我站在妳的面前,妳却感觉不到我的存在
技术方向:Flume+Kafka+Storm+Redis/Hbase+Hadoop+Hive+Mahout+Spark ... 云计算技术
转载声明:能够转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明,谢谢合作!
qq交流群:214293307
(期待与你一起学习,共同进步)
1 计数器
计数器能够方便、高速地进行计数操作。并且避免了加锁等保证了原子性的操作。
1.1 Java API 操作 HBase 计数器
public Result increment(final Increment increment)
public long incrementColumnValue(final byte [] row, final byte [] family,
final byte [] qualifier, final long amount)
public long incrementColumnValue(final byte [] row, final byte [] family,
final byte [] qualifier, final long amount, final Durability durability)
从这 3 个 HBase 提供的 计数器 API 来看,能够知道有 单列计数器 和 多列计数器
pv + 1 的 Java 示比例如以下 :
_hTable.incrementColumnValue(Bytes.toBytes("row-zhangsan-001"), Bytes.toBytes("info"), Bytes.toBytes("pv"), 1L);
1.2 Shell 操作 HBase 计数器
hbase(main):011:0> incr 'user', 'row-zhangsan-001', 'cf1:pv', 10
hbase(main):012:0> incr 'user', 'row-zhangsan-001', 'cf1:pv', -1
hbase(main):013:0> scan 'user'
ROW COLUMN+CELL
row-zhangsan-001 column=cf1:pv, timestamp=1438853474770, value=\x00\x00\x00\x00\x00\x00\x00\x09
hbase(main):014:0> get_counter 'user', 'row-zhangsan-001', 'cf1:pv', ''
COUNTER VALUE = 9
// 看以下提示,给的样例仅仅要3个參数,为什么我要打4个才可以用???
hbase(main):015:0> get_counter 'user', 'row-zhangsan-001', 'cf1:pv'
ERROR: wrong number of arguments (3 for 4)
Here is some help for this command:
Return a counter cell value at specified table/row/column coordinates.
A cell cell should be managed with atomic increment function oh HBase
and the data should be binary encoded. Example:
hbase> get_counter 'ns1:t1', 'r1', 'c1'
hbase> get_counter 't1', 'r1', 'c1'
The same commands also can be run on a table reference. Suppose you had a reference
t to table 't1', the corresponding command would be:
hbase> t.get_counter 'r1', 'c1'
hbase(main):055:0> get 'test_icv_tmp_1', 'row-zhangsan-001', 'cf1:pv'
COLUMN CELL
cf1:pv timestamp=1438853974733, value=\x00\x00\x00\x00\x00\x00\x00\x0A
1 row(s) in 0.0080 seconds
hbase(main):056:0>
1.3 单列计数器
_hTable.incrementColumnValue(Bytes.toBytes("row-zhangsan-001"), Bytes.toBytes("info"), Bytes.toBytes("pv"), 10L); // pv +10
_hTable.incrementColumnValue(Bytes.toBytes("row-zhangsan-001"), Bytes.toBytes("info"), Bytes.toBytes("pv"), -1L); // pv -1
1.4 多列计数器
pv +2 的同一时候,uv 同一时候 +1
Increment increment = new Increment(Bytes.toBytes("row"));
increment.addColumn(Bytes.toBytes("info"), Bytes.toBytes("pv"), 1L); // pv +2
increment.addColumn(Bytes.toBytes("info"), Bytes.toBytes("uv"), 1L); // uv +1
_hTable.increment(increment);
相关文章推荐
- HBase - 计数器 - 计数器的介绍以及使用 | 那伊抹微笑
- HBase - Filter - 过滤器的介绍以及使用 | 那伊抹微笑
- HBase - Filter - 过滤器的介绍以及使用 | 那伊抹微笑
- HBase - Coprocessor - 协处理器之观察者Observer(触发器)的介绍以及使用 | 那伊抹微笑
- HBase - Filter - 过滤器的介绍以及使用 | 那伊抹微笑
- HBase - Filter - 过滤器的介绍以及使用 | 那伊抹微笑
- HBase - MapReduce - 使用 MapReduce 批量操作 HBase 介绍 | 那伊抹微笑
- HBase CoProcessor介绍以及使用
- Ant介绍以及基本使用指南
- 关于datagrid的使用以及动态修改,以及使用存储过程的介绍
- .NetTiers使用以及介绍
- 关于datagrid的使用以及动态修改,以及使用存储过程的介绍
- Facebook介绍Hbase使用的文章中了SIGMOD ’11
- 安卓各种资源介绍及使用方法以及工程各文件夹的介绍
- 约束类型介绍以及使用整理
- delphi的专家工具Gexperts以及使用介绍
- Log4j 的使用以及简单介绍
- Android Resource介绍和使用以及bug记录
- 今天为大家介绍下Android的下拉单使用方法(Spinner),以及效果图。
- 一篇介绍如何使用XAMPP以及PDT开发PHP环境搭建的文章