Hbase之取出行数据指定部分(类似MySQL的Limit)
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CellScanner;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes; import java.io.IOException;
import java.util.ArrayList;
import java.util.List; /**
* Created by similarface on 16/8/22.
* 这儿实现了一个类似于MySQL的Limit的功能
*/
public class RetrievesPartsRowWithOffsetLimit {
public static void main(String args[]) throws IOException {
Configuration configuration = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(configuration);
//建立表的连接
Table table = connection.getTable(TableName.valueOf("testtable"));
Put put = new Put(Bytes.toBytes("5701"));
for (int n = 1; n <= 1000; n++) {
String num = String.format("%04d", n);
put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual"+num), Bytes.toBytes("val" + num));
}
table.put(put);
Get get1 = new Get(Bytes.toBytes("5701"));
//要求最多返回10个Cell
get1.setMaxResultsPerColumnFamily(10);
Result result1 = table.get(get1);
CellScanner scanner1 = result1.cellScanner();
//返回1-10的数据集
while (scanner1.advance()) {
System.out.println("Get 1 Cell: " + scanner1.current());
} Get get2 = new Get(Bytes.toBytes("5701"));
//要求最多返回10行
get2.setMaxResultsPerColumnFamily(10);
//跳过前面100
get2.setRowOffsetPerColumnFamily(100);
Result result2 = table.get(get2);
CellScanner scanner2 = result2.cellScanner();
//返回101-110的数据
while (scanner2.advance()) {
System.out.println("Get 2 Cell: " + scanner2.current());
}
}
}
/**
result:
Get 1 Cell: 5701/colfam1:qual0001/1471842173521/Put/vlen=7/seqid=0
Get 1 Cell: 5701/colfam1:qual0002/1471842173521/Put/vlen=7/seqid=0
Get 1 Cell: 5701/colfam1:qual0003/1471842173521/Put/vlen=7/seqid=0
Get 1 Cell: 5701/colfam1:qual0004/1471842173521/Put/vlen=7/seqid=0
Get 1 Cell: 5701/colfam1:qual0005/1471842173521/Put/vlen=7/seqid=0
Get 1 Cell: 5701/colfam1:qual0006/1471842173521/Put/vlen=7/seqid=0
Get 1 Cell: 5701/colfam1:qual0007/1471842173521/Put/vlen=7/seqid=0
Get 1 Cell: 5701/colfam1:qual0008/1471842173521/Put/vlen=7/seqid=0
Get 1 Cell: 5701/colfam1:qual0009/1471842173521/Put/vlen=7/seqid=0
Get 1 Cell: 5701/colfam1:qual0010/1471842173521/Put/vlen=7/seqid=0
Get 2 Cell: 5701/colfam1:qual0101/1471842173521/Put/vlen=7/seqid=0
Get 2 Cell: 5701/colfam1:qual0102/1471842173521/Put/vlen=7/seqid=0
Get 2 Cell: 5701/colfam1:qual0103/1471842173521/Put/vlen=7/seqid=0
Get 2 Cell: 5701/colfam1:qual0104/1471842173521/Put/vlen=7/seqid=0
Get 2 Cell: 5701/colfam1:qual0105/1471842173521/Put/vlen=7/seqid=0
Get 2 Cell: 5701/colfam1:qual0106/1471842173521/Put/vlen=7/seqid=0
Get 2 Cell: 5701/colfam1:qual0107/1471842173521/Put/vlen=7/seqid=0
Get 2 Cell: 5701/colfam1:qual0108/1471842173521/Put/vlen=7/seqid=0
Get 2 Cell: 5701/colfam1:qual0109/1471842173521/Put/vlen=7/seqid=0
Get 2 Cell: 5701/colfam1:qual0110/1471842173521/Put/vlen=7/seqid=0
**/
Hbase之取出行数据指定部分(类似MySQL的Limit)的更多相关文章
- Hbase之取出行数据指定部分+版本控制(类似MySQL的Limit)
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.CellScanner; import org. ...
- sqlserver row_number 类似 mysql中 limit 用法
select * from ( select row_number() over(ORDER BY inspecdate desc,inspectime DESC,itemorder asc ) as ...
- 架构模式数据源模式之:表数据入口(Table Data Gateway)、行数据入口(Row Data Gateway)、活动记录(Active Record)
一:表数据入口(Table Data Gateway) 表数据入口提供了用于访问单个表或者视图(也包含了联表查询)的所有SQL,通常一个表一个类.其它代码通过它来实现对数据库的交互.基于这个特点,表数 ...
- 实现HBase增量入库(HBase删除自定义时间戳行数据)
目录 1. 背景描述 2. 问题描述 3. 解决方案 1. 背景描述 目前在做音乐推荐项目,前期做排序模型优化,任务是使用模型对用户的历史音乐进行排序,有6800多万个用户,约40G的用户数据,使用H ...
- SQL查询显示行号、随机查询、取指定行数据
转自:walkingp 1.显示行号 如果数据没有删除的情况下主键与行号是一致的,但在删除某些数据,行号就与主键不一致了,这时需要查询行号就需要用新的方法,在SQL Server2005之前,需要使用 ...
- pandas数据处理基础——筛选指定行或者指定列的数据
pandas主要的两个数据结构是:series(相当于一行或一列数据机构)和DataFrame(相当于多行多列的一个表格数据机构). 本文为了方便理解会与excel或者sql操作行或列来进行联想类比 ...
- mssql sqlserver 禁止删除数据表中指定行数据(转自:http://www.maomao365.com/?p=5323)
转自:http://www.maomao365.com/?p=5323 摘要:下文主要讲述,如何禁止删除数据表中指定行数据 最近收到用户一个需求,禁止所有人删除”表A”中,ID 为1.2.3.4.5的 ...
- DataTables获取指定元素的行数据
法1: 用jquey获取,var row = $('.edit').parent().parent(); 缺点:只能获取dom上的东西,不能获取没有渲染的数据 法2: 首先绑定行号到元素上 $('#e ...
- HBase(六)HBase整合Hive,数据的备份与MR操作HBase
一.数据的备份与恢复 1. 备份 停止 HBase 服务后,使用 distcp 命令运行 MapReduce 任务进行备份,将数据备份到另一个地方,可以是同一个集群,也可以是专用的备份集群. 即,把数 ...
随机推荐
- ural 1113,jeep problem
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1113 网上的解答铺天盖地.我硬是花了两天才懂了点. wiki上的解释:https://e ...
- MDK中 use microlib
microlib 与缺省 C 库之间的主要差异是: microlib 不符合 ISO C 库标准. 不支持某些 ISO 特性,并且其他特性具有的功能也较少. microlib 不符合 IEEE 754 ...
- 对table的tr使用display:block显示colspan失效问题的解决
qqqq <table> <tr> <td id="qqq" colspan="3" style="display:no ...
- lua中for循环
, do ') end 显示的结果是 xbwang@xbwang-desktop:~/Desktop$ th for.lua 其他语言只会输出一个2,lua的这个for循环输出了两个2 Lua 编程语 ...
- nylg 小M的因子和
小M的因子和 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 小M在上课时有些得意忘形,老师想出道题目难住他.小M听说是求因子和,还是非常得意,但是看完题目是求A的B ...
- VS2015使用技巧 打开代码片段C#部分
镇场诗: 大梦谁觉,水月中建博客.百千磨难,才知世事无常. 今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ 1. ...
- 编写一个Java程序,计算一下1,2,…,9这9个数字可以组成多少个互不相同的、无重复数字的三位偶数。
package a; public class SanWeiOuShu { public static void main(String[] args) { String str="1234 ...
- CodeForces 567C Geometric Progression
Geometric Progression Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- 遇到问题-----JS中设置window.location.href跳转无效(在a标签里或这form表单里)
问题情况 JS中设置window.location.href跳转无效 代码如下: ? 1 2 3 4 5 6 7 8 <script type="text/javascript&quo ...
- linux 中的快捷键
终端快捷键 tab=补全 ctrl+a=开始位置 ctrl+e=最后位置 ctrl+k=删除此处至末尾所有内容 ctrl+u=删除此处至开始所有内容 ctrl+d=删除当前字母 ctrl+w=删除此处 ...