Hbase条件筛选

本文介绍了一种在HBase中实现模糊查询的方法,通过设定时间戳范围并结合内置过滤器来检索特定列的数据。该方法适用于需要按日期查找记录的应用场景。

需求来自于,模糊查找当天的所有记录,并查找对应列的记录数

public static void main(String[] args) throws Exception{
//创建HBase连接 Configuration conf
= HBaseConfiguration.create();
//设定需要查询的表 HTable table
= new HTable(conf,"EVENT_LOG_LBS_HIS"); Scan scan = new Scan();
//设定模糊时间戳 String startStr
= "-20160530";
//使用Hbase内置过滤器 scan.setFilter(findCount(startStr)); ResultScanner rowscan
= table.getScanner(scan); int i = 1;
//遍历结果
for(Result rs : rowscan){ System.out.println("第" + i + "条: rowkey= " + Bytes.toString(rs.getRow())); i++;
//根据结果行中某一列的值,进行条件筛选 String aaa
= Bytes.toString(rs.getValue("f1".getBytes(),"LS_channel_type".getBytes())); if(aaa.equals("2"){ System.out.println(Bytes.toString(rs.getRow())); } } public static FilterList findCount(String startstr){ Filter filter = new RowFilter(CompareFilter.CompareOp.GREATER_OR_EQUAL,new RegexStringComparator(startstr)); return filter; }

 其实可以都写成内置过滤器,不过HBase还没有深入学习,暂时先这样写啦~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值