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还没有深入学习,暂时先这样写啦~

  • 相关阅读:
    Python基础学习Day2
    Python基础学习
    字符串
    function对象
    GCN入门理解
    L1、L2正则化详解
    Matplotlib数据可视化基础
    sklearn 中模型保存的两种方法
    一文弄懂神经网络中的反向传播法——BackPropagation
    seaborn可视化
  • 原文地址:https://www.cnblogs.com/yangsy0915/p/5543403.html
Copyright © 2011-2022 走看看