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 任务进行备份,将数据备份到另一个地方,可以是同一个集群,也可以是专用的备份集群. 即,把数 ...
随机推荐
- 使用 /proc 文件系统来访问 linux操作系统 内核的内容 && 虚拟文件系统vfs及proc详解
http://blog.163.com/he_junwei/blog/static/19793764620152743325659/ http://www.01yun.com/other/201304 ...
- wpfのuri(让你完全明白wpf的图片加载方式以及URI写法)
绝对 pack WPF URI pack://application:,,,/是协议:“,,,”是“///”的变体 1.资源文件 — 本地程序集 Uri uri = new Uri("pac ...
- Linux 性能监控、测试、优化工具
Linux 平台上的性能工具有很多,眼花缭乱,长期的摸索和经验发现最好用的还是那些久经考验的.简单的小工具.系统性能专家 Brendan D. Gregg 在最近的 LinuxCon NA 2014 ...
- 关于stack around the variable “” was corrupted问题
很坑爹的问题,异常信息表示我的缓冲区如数组越界了,可是老子明明没有越界. 解决方法:关闭vs检查代码是否越界的功能: 属性->c/c++->代码生成->基本运行时检查,改为默认值
- 第五课 SharedPrefereneces
SharedPreferences总结: 一.SharedPreferences特点 1.本质是基于xml文件储存key-value对数据: 2.SharedPreferences对象本身只能获取数据 ...
- Cheatsheet: 2013 09.01 ~ 09.09
.NET Multi Threaded WebScraping in CSharpDotNetTech .NET Asynchronous Patterns An Overview of Projec ...
- webAPI获得链接客户端IP地址
public static class HttpRequestMessageExtensions { private const string HttpContext = "MS_HttpC ...
- Atlassian如何实施DevOps
DevOps是推动开发和运维团队之间沟通和协作的手段.它不是一个工具或产品.相反,其成功的首要因素就是文化.目的是更快的创新和更好的客户体验. "2015年DevOps状态报告"调 ...
- 基础!winForm客户端最常用的几个基本属性
客户端应用程序 - 是需要安装在用户电脑上才可以使用的程序特点:不需要联网也可以打开使用部分功能但是现在的情况是许多功能依然需要互联网的支持 代码部分在用户电脑上执行 WinForm常用窗体属性: 布 ...
- spring+hibernate 实体类注解问题
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.Ann ...