zoukankan      html  css  js  c++  java
  • 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还没有深入学习,暂时先这样写啦~

  • 相关阅读:
    mysql 取出每科成绩前两名
    mysql 数据库以及sql 的优化
    Twitter开源分布式自增ID算法snowflake
    SVN 冲突
    VUE 入门 1 列表、if判断 、双向绑定
    Roadblock
    最大子序和
    SOLDIERS
    绿豆蛙的归宿
    Place the Robots
  • 原文地址:https://www.cnblogs.com/yangsy0915/p/5543403.html
Copyright © 2011-2022 走看看