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)的更多相关文章

  1. Hbase之取出行数据指定部分+版本控制(类似MySQL的Limit)

    import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.CellScanner; import org. ...

  2. sqlserver row_number 类似 mysql中 limit 用法

    select * from ( select row_number() over(ORDER BY inspecdate desc,inspectime DESC,itemorder asc ) as ...

  3. 架构模式数据源模式之:表数据入口(Table Data Gateway)、行数据入口(Row Data Gateway)、活动记录(Active Record)

    一:表数据入口(Table Data Gateway) 表数据入口提供了用于访问单个表或者视图(也包含了联表查询)的所有SQL,通常一个表一个类.其它代码通过它来实现对数据库的交互.基于这个特点,表数 ...

  4. 实现HBase增量入库(HBase删除自定义时间戳行数据)

    目录 1. 背景描述 2. 问题描述 3. 解决方案 1. 背景描述 目前在做音乐推荐项目,前期做排序模型优化,任务是使用模型对用户的历史音乐进行排序,有6800多万个用户,约40G的用户数据,使用H ...

  5. SQL查询显示行号、随机查询、取指定行数据

    转自:walkingp 1.显示行号 如果数据没有删除的情况下主键与行号是一致的,但在删除某些数据,行号就与主键不一致了,这时需要查询行号就需要用新的方法,在SQL Server2005之前,需要使用 ...

  6. pandas数据处理基础——筛选指定行或者指定列的数据

    pandas主要的两个数据结构是:series(相当于一行或一列数据机构)和DataFrame(相当于多行多列的一个表格数据机构). 本文为了方便理解会与excel或者sql操作行或列来进行联想类比 ...

  7. mssql sqlserver 禁止删除数据表中指定行数据(转自:http://www.maomao365.com/?p=5323)

    转自:http://www.maomao365.com/?p=5323 摘要:下文主要讲述,如何禁止删除数据表中指定行数据 最近收到用户一个需求,禁止所有人删除”表A”中,ID 为1.2.3.4.5的 ...

  8. DataTables获取指定元素的行数据

    法1: 用jquey获取,var row = $('.edit').parent().parent(); 缺点:只能获取dom上的东西,不能获取没有渲染的数据 法2: 首先绑定行号到元素上 $('#e ...

  9. HBase(六)HBase整合Hive,数据的备份与MR操作HBase

    一.数据的备份与恢复 1. 备份 停止 HBase 服务后,使用 distcp 命令运行 MapReduce 任务进行备份,将数据备份到另一个地方,可以是同一个集群,也可以是专用的备份集群. 即,把数 ...

随机推荐

  1. Web项目后台测试流程

    1. 本地下载项目源码 1. Git clone项目代码到本地(本地项目代码1)并fetch: 2. Switch到master分支: 3. Create测试分支(例如:test1)并勾选“Switc ...

  2. linux下查看电脑配置

    1. 查看cpu ~$ cat /proc/cpuinfo 2. 查看内存占用 ~$ cat /proc/meminfo 3. 硬盘分区 $ cat /proc/partitions 4. ubunt ...

  3. vim中如何替换

    1) 文件内全部替换:   :%s#abc#123#g (如文件内有#,可用/替换,:%s/abc/123/g)   --注:把abc替换成123   (或者: %s/str1/str2/g 用str ...

  4. SQL Server中常用的SQL语句

    1.概述 名词 笛卡尔积.主键.外键 数据完整性 实体完整性:主属性不能为空值,例如选课表中学号和课程号不能为空 参照完整性:表中的外键取值为空或参照表中的主键 用户定义完整性:取值范围或非空限制,例 ...

  5. 2015 AlBaath Collegiate Programming Contest B

    Description Yaaaay, Haven't you heard the news? Bakaloria results are out! And Reem had very good gr ...

  6. Struts2应用的开发流程

    Struts2的开发流程 为了能够在eclipse中使用Struts2在进行开发时,需要根据需要导入一些有关的jar包: 在官网下载相关的压缩包,这里下载了两个:struts-2.3.30-all.z ...

  7. 用于 ‘Suse‘ Linux 包管理的 Zypper 命令大全

    SUSE( Software and System Entwicklung,即软件和系统开发.其中‘entwicklung‘是德语,意为开发)Linux 是由 Novell 公司在 Linux 内核基 ...

  8. 模板页显示Excel数据Gridview增删改查

    <%@ Page Title="主页" Language="C#" MasterPageFile="~/Site.master" Au ...

  9. 在包a中新建一个类A,在类A中有一个int add(int m)方法,用来求1+2+…+m 的和。在包b中新建一个类B,在类B中有一个int cheng(int n)方法,用来求n! 的结果。在包c中新建一个主类C,调用A、B中的方法输出1+2+…+30的和, 以及5!的计算结果。

    package a; public class A { public void add(int m) { int sum=0; for (int i = 1; i <=m; i++) { sum ...

  10. excel在一个图表内,显示折线图和柱状图

      折线图和柱状图,在同一个图表中拆分显示   一个图,设置主坐标轴 另外一个图,设置次坐标轴     拆分,通过调整纵坐标的最小值和最大值来实现     关于图表的标题,选中图表,选择布局,然后图表 ...