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 任务进行备份,将数据备份到另一个地方,可以是同一个集群,也可以是专用的备份集群. 即,把数 ...
随机推荐
- Uva 10118 免费糖果
题目链接:https://uva.onlinejudge.org/external/101/10118.pdf 参考:http://www.cnblogs.com/kedebug/archive/20 ...
- 2016 Al-Baath University Training Camp Contest-1 B
Description A group of junior programmers are attending an advanced programming camp, where they lea ...
- Java提高篇---Map总结
一.Map概述 首先先看Map的结构示意图 Map:"键值"对映射的抽象接口.该映射不包括重复的键,一个键对应一个值. SortedMap:有序的键值对接口,继承Map接口. Na ...
- WebForm分页浏览
1.封装类 //封装类 using System; using System.Collections.Generic; using System.Web; /// <summary> // ...
- Ajax 用法
Ajax 用法 var total=100; var orderName='sssss'; var orderDescrib='dddd ...
- DataSet 关系
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 第二课 android项目结构
- Python import 指定目录中的模块
#coding=utf-8 import os,sys sys.path.append('test') # 下级目录(text) parentdir = os.path.dirname(os.path ...
- SignalR记录
服务端检索数据库,有跟新,推送给客户端 1: GlobalHost.ConnectionManager.GetHubContext<tvHub>().Clients.Client(Clie ...
- Creating List Item in Oracle D2k
Special Tips for List Items in Oracle D2k In this section, I shall discuss some special tips and tec ...