Hbase之取出行数据指定部分(类似MySQL的Limit)
2016-08-22 13:10
330 查看
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)
- mysql && hbase && hive && hdfs(部分) 数据互导
- MySQL——union(合并结果集)、limit(获取部分数据)、关于MySQL中常用数据类型
- Mysql中随机挑选指定数量的数据
- MySQL 按条件导出某部分数据
- mysql中limit的用法详解[数据分页常用]
- Mysql如何指定新插入的数据的起始自增主键id
- mysql中limit的用法详解(数据分页常用)
- SQL、MySQL、Oracle、 Sqlite、Informix数据库查询指定条数数据的方法
- mysql根据指定条件备份数据
- mysql中limit的用法详解[数据分页常用]
- mysql更新数据limit问题
- [MySQL FAQ]系列 -- 如何为一个数据表指定字符集
- Hbase通过 Mapreduce 写入数据到Mysql
- mysql 主从同步如何 把从数据的版本升级到指定的版本
- Mysql指定编码导入导出数据
- MySQL 如何只导出 指定的表 的表结构和数据
- mysql替换字段里数据内容部分字符串
- 如何优化Mysql千万级快速分页,limit优化快速分页,MySQL处理千万级数据查询的优化方案!(zz)
- MYSQL使用mysqldump导出某个表的部分数据