import org.apache.hadoop.conf.Configuration;
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; /**
* 遍历获取数据
*/
public class ScanAccessData {
public static void main(String[] args) throws IOException {
Configuration configuration = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(configuration);
//建立表的连接
Table table = connection.getTable(TableName.valueOf("testtable"));
//创建一个空的Scan实例
Scan scan1 = new Scan();
//在行上获取遍历器
ResultScanner scanner1 = table.getScanner(scan1);
//打印行的值
for (Result res : scanner1) {
System.out.println(res);
}
//关闭释放资源
scanner1.close(); Scan scan2 = new Scan();
//添加限定列族
scan2.addFamily(Bytes.toBytes("colfam1"));
ResultScanner scanner2 = table.getScanner(scan2);
for (Result res : scanner2) {
System.out.println(res);
}
scanner2.close(); Scan scan3 = new Scan();
//添加限定列族 列分隔 行偏移
scan3.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col-5")).
addColumn(Bytes.toBytes("colfam2"), Bytes.toBytes("col-33")).
setStartRow(Bytes.toBytes("row-10")).
setStopRow(Bytes.toBytes("row-20"));
ResultScanner scanner3 = table.getScanner(scan3);
for (Result res : scanner3) {
System.out.println(res);
}
scanner3.close(); Scan scan4 = new Scan();
scan4.addColumn(Bytes.toBytes("colfam1"),
Bytes.toBytes("col-5")).
setStartRow(Bytes.toBytes("row-10")).
setStopRow(Bytes.toBytes("row-20"));
ResultScanner scanner4 = table.getScanner(scan4);
for (Result res : scanner4) {
System.out.println(res);
}
scanner4.close(); Scan scan5 = new Scan();
//添加倒序
scan5.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col-5")).
setStartRow(Bytes.toBytes("row-20")).
setStopRow(Bytes.toBytes("row-10")).
setReversed(true);
ResultScanner scanner5 = table.getScanner(scan5);
for (Result res : scanner5) {
System.out.println(res);
}
scanner5.close();
}
}

Hbase之遍历获取数据的更多相关文章

  1. 8 Hbase get方式获取数据

    package com.hikvision.hbase.vertify.test; import org.apache.hadoop.conf.Configuration; import org.ap ...

  2. HBase 高性能获取数据(多线程批量式解决办法) + MySQL和HBase性能测试比较

    摘要:   在前篇博客里已经讲述了通过一个自定义 HBase Filter来获取数据的办法,在末尾指出此办法的性能是不能满足应用要求的,很显然对于如此成熟的HBase来说,高性能获取数据应该不是问题. ...

  3. 一个自定义 HBase Filter -“通过RowKeys来高性能获取数据”

    摘要: 大家在使用HBase和Solr搭建系统中经常遇到的一个问题就是:“我通过SOLR得到了RowKeys后,该怎样去HBase上取数据”.使用现有的Filter性能差劲,网上也没有现成的自定义Fi ...

  4. Hbase之尝试使用错误列族获取数据

    import com.google.common.base.Strings; import org.apache.hadoop.conf.Configuration; import org.apach ...

  5. 无限遍历,Python实现在多维嵌套字典、列表、元组的JSON中获取数据

    背景 在做接口自动化的过程中,接口返回的数据是  列表字典循环嵌套  格式的,所以怎样通过一个key值,获取到被包裹了多层的目标数据成为了摆在我面前的一个问题. 一开始没想自己写,但是搜索后发现虽然很 ...

  6. hbase各种遍历查询shell语句 包含过滤组合条件

    import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Li ...

  7. 从SQLite获取数据完成一个产品信息展示

    在ios实际开发当中,我们常常用到Core Data做为数据储存首选.但在处理一些大量复杂的数据值且数据之间相互关联的时候,这就不得不使用关系型数据库来实现.例如一个导航程序,自身应该包含大量的地图自 ...

  8. js声明json数据,打印json数据,遍历json数据

    1.js声明json数据: 2.打印json数据: 3.遍历json数据 //声明JSON var json = {}; json.a = 1; //第一种赋值方式(仿对象型) json['b'] = ...

  9. python数据库操作常用功能使用详解(创建表/插入数据/获取数据)

    实例1.取得MYSQL版本 复制代码 代码如下: # -*- coding: UTF-8 -*-#安装MYSQL DB for pythonimport MySQLdb as mdbcon = Non ...

随机推荐

  1. windows下mysql自动定时备份bat

    @echo off : basedataset ip=192.168.12.41set user=rootset password=12456 set databaseName=test set /a ...

  2. MVCAction接受与返回

    //Action方法接受有:如下四种: //Test(int id) 接受url路由中配置的同名参数 //通过request.Form/request.querystring 接受(get) //Te ...

  3. 腾讯微博模拟登陆+数据抓取(java实现)

    不多说,贴出相关代码. 参数实体: package token.def; import java.io.Serializable; import java.util.Properties; publi ...

  4. sh和bash的区别

    在鸟哥的私房菜的一书中,介绍了UNIX的版本以及众多的SHELL版本. 早在UNIX年代,发展者众多,所以由于shell依据发展者的不同就有许多版本,比如sh,C SHell,K SHell,还有TC ...

  5. BZOJ 3672 [Noi2014]购票 (熟练剖分+凸壳维护)

    题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3672 题意:给出一棵有根树(1为根),边有长度.每个点u有三个属性(len[u], ...

  6. 【翻译】《深入解析windows操作系统第6版下册》第10章:内存管理

    [翻译]<深入解析windows操作系统第6版下册>第10章:内存管理(第一部分) [翻译]<深入解析windows操作系统第6版下册>第10章:内存管理(第二部分) [翻译] ...

  7. TeeChart中 Line的Clear方法

    需要注意的是,如果设置了Line.Smoothed=true; 那么调用Clear是无效的,虽然清除了曲线上的点. 但是界面上的曲线,并没有消失. 所以,在每一次Line.Clear();之前,必须确 ...

  8. Creating HTML table with vertically oriented text as table header 表头文字方向

    AS an old question, this is more like info or reminder about vertical margin or padding in % that ta ...

  9. SpringMVC 服务器端验证

    1.导入JSR303验证类库Jar包2.在MVC的配置文件中添加<mvc:annotation-driven/>的配置3.在MVC的配置文件中添加验证器的配置4.在接收表单数据的类中添加验 ...

  10. C#中实现多继承的方法

    有一个类叫老虎,还有一个类叫苍蝇.现在新创一个超级老虎类,一种可以飞的老虎,超级老虎由于同时也继承自苍蝇 namespace Interface { //飞的接口 public interface I ...