前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Hbase条件筛选

Hbase条件筛选

作者头像
用户3003813
发布2018-09-06 14:18:03
1.5K0
发布2018-09-06 14:18:03
举报
文章被收录于专栏:个人分享

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

代码语言:javascript
复制
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还没有深入学习,暂时先这样写啦~

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-05-30 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档